簡體   English   中英

Process.Start("explorer.exe", Path) 無法打開正確的文件夾

[英]Process.Start("explorer.exe", Path) can't open the right folder

正如標題所說,Process.Start("explorer.exe", Path) 沒有在資源管理器中打開正確的路徑。

我希望打開的路徑是“C:/Users/%username%/Documents/My Games/FarmingSimulator2022/mods”

它實際打開的路徑是“This PC > Document”或者可以寫成“C:/Users/%username%/Documents”

順便說一句,我試過@Path,沒有“@”只是路徑,它是一樣的。

我的代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace FS22_ModManagerCore
{
    public partial class MainWindow : Form
    {
        readonly string Username = Environment.UserName;
        public string GameDataPath;
        public string GameSettingXMLpath;
        public string ModFolder;
        
        public MainWindow()
        {
            InitializeComponent();
        }
        
        private void Btn_GetModPath_Click(object sender, EventArgs e)
        {
            GameDataPath = "C:/Users/" + Username + "/Documents/My Games/FarmingSimulator2022";
            GameSettingXMLpath = "C:/Users/" + Username + "/Documents/My Games/FarmingSimulator2022/gameSettings.xml";
            
            if (Directory.Exists(GameDataPath))
            {
                if (File.Exists(GameSettingXMLpath))
                {
                    ModFolder = GetModPath(GameDataPath, GameSettingXMLpath);
                }
                else
                {
                    MessageBox.Show("Game needs to run at least once! ExCode: 1002");
                }
            }
            else
            {
                MessageBox.Show("Gamedata folder doesn't exist! ExCode: 1001");
            }
        }
        
        public static string GetModPath(string GameDataPath, string XMLPath)
        {
            string ReturnPath = "";
            XmlDocument gameSetting = new();
            gameSetting.Load(XMLPath);
            XmlNode node = gameSetting.DocumentElement.SelectSingleNode("/gameSettings/modsDirectoryOverride");
            string IsActive = node.Attributes["active"].InnerText;
            if (IsActive == "false")
            {
                ReturnPath = GameDataPath + "/mods";
                MessageBox.Show(ReturnPath);    //DEBUG ONLY
                Clipboard.SetText(ReturnPath);  //DEBUG ONLY
                Process.Start("explorer.exe", ReturnPath);  //<<<<<< ISSUE !!!!!!!!
                return ReturnPath;
            }
            else
            {
                return ReturnPath;  //PLACE HOLDER
            }
            //string CusomPath = node.Attributes["directory"].InnerText;
        }
    }
}

Windows 路徑使用\而不是/ 它們通常可以互換,但並非總是如此。

這個

C:\>explorer.exe "C:\Users\David\Documents\My Games\FarmingSimulator2022\mods"

作品。 所以這也是:

System.Diagnostics.Process.Start("explorer.exe", @"""C:\Users\David\Documents\My Games\FarmingSimulator2022\mods""");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM