Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open a folder in Windows Explorer?

Tags:

c#

explorer

I don't need any kind of interface. I just need the program to be an .exe file that opens a directory (eg. F:).

What kind of template would I use in C#? Would something other than Visual Studio work better? Would a different process entirely work better?

like image 361
Sam Beach Avatar asked Sep 04 '15 09:09

Sam Beach


People also ask

How do I open a folder in Explorer?

There are a number of ways to display a folder in File Explorer: Click on a folder if it's listed in the Navigation pane. Click on a folder in the Address bar to display its subfolders. Double-click on a folder in the file and folder listing to display any subfolders.

Why can't I see a folder in Windows Explorer?

In the File Explorer Options window, click on the "View" tab. Step 3. Check the option "Show hidden files, folders or drives". Also, uncheck "Hide protected operating system files" and "Hide extensions for known file types".

How do I go to a specific folder in Windows?

This button can be found in the lower-left corner of the screen, and may just be a Windows logo. Click the Computer or File Explorer button. In Windows 10, this looks like a folder and can be found on the left side of the menu, or in your Windows task bar at the bottom of the screen.


2 Answers

In C# you can do just that:

Process.Start(@"c:\users\");

This line will throw Win32Exception when folder doesn't exists. If you'll use Process.Start("explorer.exe", @"C:\folder\"); it will just opened another folder (if the one you specified doesn't exists).

So if you want to open the folder ONLY when it exists, you should do:

try
{
    Process.Start(@"c:\users22222\");
}
catch (Win32Exception win32Exception)
{
    //The system cannot find the file specified...
    Console.WriteLine(win32Exception.Message);
}
like image 191
voytek Avatar answered Sep 24 '22 18:09

voytek


Create a batch file , for example open.bat

And write this line

%SystemRoot%\explorer.exe "folder path"

If you really want to do it in C#

  class Program
{
    static void Main(string[] args)
    {
        Process.Start("explorer.exe", @"C:\...");
    }
 }
like image 42
Viva Avatar answered Sep 22 '22 18:09

Viva