Open a folder with File explorer using .bat
Categories:
Open a Folder with File Explorer Using a Batch File

Learn how to create a simple batch (.bat) file to quickly open any specified folder in Windows File Explorer, enhancing your workflow efficiency.
Batch files provide a powerful yet simple way to automate repetitive tasks in Windows. One common use case is to quickly open a specific folder in File Explorer. This can be incredibly useful for accessing frequently used directories, project folders, or network shares with a single click, saving you time from navigating through multiple levels of directories.
The Basic Command: start explorer
The core command for opening File Explorer in a batch file is start explorer. This command is versatile and can be used with various arguments to specify the target folder. When executed, it launches a new File Explorer window displaying the contents of the specified path.
start explorer "C:\Path\To\Your\Folder"
Basic command to open a specific folder
"C:\Program Files\My App".Opening the Current Directory
If you want the batch file to open the folder where the batch file itself is located, you can use the special variable %~dp0. This variable expands to the drive letter and path of the batch file. This is particularly useful for portable scripts or when you distribute a batch file alongside related content.
start explorer "%~dp0"
Batch file to open its own directory

Workflow for opening a folder via batch file
Opening a Relative Path
You can also open a folder relative to the batch file's location. For instance, if your batch file is in C:\Projects\MyProject and you want to open C:\Projects\MyProject\Docs, you can specify a relative path. This keeps your batch file flexible even if the parent directory moves.
start explorer "%~dp0Docs"
Opening a subfolder relative to the batch file
%~dp0 ensures the path is always relative to the batch file's actual location.Creating the Batch File
Creating a batch file is straightforward. You simply need a text editor like Notepad. Follow these steps to create your own batch file.
1. Open Notepad or any text editor.
Launch Notepad from your Start Menu or by typing notepad in the Run dialog (Win+R).
2. Enter the command.
Type the start explorer command followed by the path you wish to open. For example: start explorer "D:\My Important Files".
3. Save the file.
Go to File > Save As.... In the 'Save as type' dropdown, select 'All Files (.)'. Name your file with a .bat extension, for example, OpenMyFolder.bat. Choose a convenient location to save it.
4. Execute the batch file.
Navigate to where you saved the .bat file and double-click it. File Explorer should open to the specified directory.