How do I open an Explorer window in a given directory from cmd.exe?
Asked Answered
N

8

50

I see how to launch many other programs from a batch file, but I can't find a command like open on Mac OS X. Does such a tool exist on Windows? Powershell, or a Windows API call from an executable would also work.

Or, put another way, how can I invoke Windows default "Open" handler for a file from a batch file or powershell script?

Numb answered 3/8, 2010 at 21:28 Comment(3)
start .. In Linux the equivalent is xdg-open .Cacilia
This is the answer you are looking for > use start . Worse
Why was this marked off-topic? I think it is a valid programming question. Maybe rephrased as "how do I invoke the operating system default 'open' handler for a file from a shell script on windows" might make this more clear?Caryopsis
M
49

In Windows you can open Explorer with the following command:

C:\Users\Leniel>start %windir%\explorer.exe

If you want it to open a specific folder, do this for example:

C:\Users\Leniel>start %windir%\explorer.exe "C:\Users\Leniel\Desktop"
Manipular answered 3/8, 2010 at 21:31 Comment(4)
You can usually omit the explorer entirely: start "c:\mydir"Mcginley
Also when launching a GUI program start is entirely unneeded. Furthermore, explorer is in the %PATH%, so explorer someDir suffices in any case.Misreckon
@mandrill: That would launch another console window with c:\mydir as its title ;-)Misreckon
Note that it is important to use "start" rather than invoking "explorer.exe" directly. Invoking it directly creates a new "explorer.exe" process (with associated memory) rather than opening a new window within the existing Explorer process.Telesthesia
F
34

You can just try

start .

This will open file explorer directly with the current directory path.

Foredoom answered 9/2, 2021 at 11:28 Comment(3)
This is perfect answer :)Revive
Only six keys touched. Fast.Inceptive
this is exact answerCurling
M
33

The direct equivalent of OS X's open is start in cmd.

start foo.txt

would launch Notepad (or whatever text editor you're using),

start http://example.com

would launch your browser,

start \someDirectory

will launch Explorer, etc.

Care has to be taken with arguments in quotes, as start will interpret the first quoted argument as the window title to use, so something like

start "C:\Users\Me\Folder with spaces\somedocument.docx"

will not work as intended. Instead prepend an empty quoted argument in that case:

start "" "C:\Users\Me\Folder with spaces\somedocument.docx"

Note that start isn't a separate program but a shell-builtin. So to invoke this from an external program you have to use something like

cmd /c start ...

The equivalent in PowerShell is either Start-Process or Invoke-Item. The latter is probably better suited for this task.

Invoke-Item foo.txt  # launches your text editor with foo.txt
Invoke-Item .        # starts Explorer in the current directory

As for the Windows API, you're looking for ShellExecute with the open verb.

Misreckon answered 9/8, 2010 at 10:30 Comment(1)
"start . " opens the current directory in the explorerBesotted
P
3

"explorer.exe ." worked for me.

explorer.exe .

IMO - As we need to open "Windows Explorer" from cmd prompt, "explorer.exe ." is easy to remember.

Persiflage answered 7/4, 2021 at 11:28 Comment(1)
This also works from inside Jupyter Notebook if you spawn out by typing "!explorer.exe ." although it opens the Explorer window UNDER the Jupyter NB.Coleridge
I
1

You can try this syntax:

explorer.exe folder_path

example:

explorer.exe D:\Movies
Impermanent answered 20/1, 2021 at 17:31 Comment(0)
I
1

You can open any folder in explorer using simply

explorer <directory path>
Impart answered 13/5, 2023 at 16:5 Comment(0)
E
1

How about (you don't need the .exe at the end)

explorer .

It will open the current window

Expletive answered 9/12, 2023 at 8:22 Comment(0)
D
0

I don't know you guys, but none of the above examples worked on BAKCSTAGE. Yes those surely work on NORMAL remote session. Any or most of those example gave me a GUI message saying explorer.exe "Server execution failed" and OK button

I just want to have a .bat on my TOOLBOX to open windows explorer in a specific folder that I need to work daily. But probably I have to put a small explorer/type of software as I always did before. I personally use this one, if you think it might help you guys. Explorer++ https://explorerplusplus.com/ You can unzip it, delete all associates files and leave the .exe alone in the toolbox, it works like a charm. To PRESET an specific folder to open with: OPTIONS->GENERAL->GENERAL SETTINGS->DEFAULT NEW TAB FOLDER.

It's an open source, it says.

Have fun. Comment if that helped you.

Darees answered 27/6 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.