繁体   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