正如標題所說, 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;
}
}
}
uj5u.com熱心網友回復:
Windows 路徑使用\not /。它們通常可以互換,但并非總是如此。
這
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""");
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/430772.html
