如何在Windows资源管理器中打开文件夹?

Sam*_*ach 3 c# explorer

我不需要任何接口.我只需要程序是一个.exe打开目录的文件(例如F :).

我会在C#中使用什么样的模板?除Visual Studio之外的其他东西会更好吗?不同的流程会完全更好地运作吗?

Viv*_*iva 9

创建批处理文件,例如open.bat

写下这一行

%SystemRoot%\explorer.exe "folder path"
Run Code Online (Sandbox Code Playgroud)

如果你真的想在C#中做到这一点

  class Program
{
    static void Main(string[] args)
    {
        Process.Start("explorer.exe", @"C:\...");
    }
 }
Run Code Online (Sandbox Code Playgroud)


voy*_*tek 8

C#你可以做到这一点:

Process.Start(@"c:\users\");
Run Code Online (Sandbox Code Playgroud)

Win32Exception当文件夹不存在时,该行将抛出.如果您将使用Process.Start("explorer.exe", @"C:\folder\");它将只打开另一个文件夹(如果您指定的文件夹不存在).

所以,如果你要打开的文件夹只有当它的存在,你应该做的:

try
{
    Process.Start(@"c:\users22222\");
}
catch (Win32Exception win32Exception)
{
    //The system cannot find the file specified...
    Console.WriteLine(win32Exception.Message);
}
Run Code Online (Sandbox Code Playgroud)