The basic command to open a file from Command Prompt
To open a file using Command Prompt, type the full path to the file or the program that opens it, then press Enter. The simplest method is to type the filename directly if you are already in the folder where it lives — for example, document.txt or photo.jpg — and Command Prompt will open it in whatever program Windows has set as the default for that file type.
If the file is in a different folder, you need the full path. For a file on your Desktop called budget.xlsx, you would type C:\Users\YourUsername\Desktop\budget.xlsx and press Enter. Windows will open it in Excel or whatever spreadsheet program you have installed.
If nothing happens when you press Enter, the file path is wrong, the file does not exist, or Command Prompt cannot find a program to open that file type. The error message will tell you which one.
Key Takeaways
- Type the filename alone if you are in the same folder, or the full path starting with C:\ if the file is elsewhere.
- Command Prompt opens files using whatever default program Windows has set for that file type.
- Use cd to change folders first, which makes typing shorter and reduces path errors.
- If a filename has spaces, wrap the entire path in quotation marks: "C:\Users\Your Name\My Documents\file name.txt"
- You can also type the program name first, then the file path, to choose which program opens the file.
Changing folders to make file paths shorter
If you need to open several files from the same folder, change to that folder first using the cd command. Type cd Desktop to move to your Desktop folder, or cd C:\Users\YourUsername\Documents to move to Documents. After you change folders, you only need to type the filename, not the whole path.
To see what folder you are currently in, type cd by itself and press Enter. Command Prompt will print the full path. To move up one level (to the parent folder), type cd .. and press Enter.
Opening a file with a specific program
By default, Command Prompt opens files with the program Windows thinks should handle them. If you want to open a text file with Notepad instead of Word, or a photo with Paint instead of your default viewer, type the program name first, then the file path.
For example, notepad C:\Users\YourUsername\Desktop\notes.txt will open that file in Notepad no matter what your default is. Other common programs are mspaint for Paint, calc for Calculator, and explorer to open a folder in File Explorer.
If the program is not in a standard Windows folder, you need the full path to the program itself. If you are unsure where a program is installed, right-click it in the Start menu, select "Open file location", and look at the path shown in the address bar.
Handling filenames with spaces and special characters
If a filename or folder name has spaces, you must wrap the entire path in quotation marks. For example, "C:\Users\Your Name\My Documents\Monthly Budget.xlsx" will work, but C:\Users\Your Name\My Documents\Monthly Budget.xlsx without quotes will fail because Command Prompt reads the space as a separator between commands.
Special characters like parentheses, ampersands, and percent signs can also cause problems. Wrapping the path in quotation marks fixes most of these. If it still does not work, try renaming the file to remove spaces and special characters, then try again.
Checking if a file exists before you try to open it
If you are not sure whether a file is in the folder you think it is, use the dir command to list all files in the current folder. Type dir and press Enter, and Command Prompt will show you every file and subfolder. You can also type dir /s to search in subfolders too, though this takes longer.
If you know part of the filename but not all of it, use a wildcard. Type dir *.txt to see all text files, or dir budget* to see all files that start with "budget". Once you see the exact filename, you can copy it and paste it into your open command to avoid typos.
Common errors and what they mean
If you see "The system cannot find the file specified", the path is wrong or the file does not exist. Check that you typed the path correctly, that the file is actually in that folder, and that you used quotation marks if the path has spaces.
If you see "The system cannot find the path specified", the folder itself does not exist. Use dir to check what folders are actually there, or use File Explorer to navigate to the file and copy the path from the address bar.
If the file opens but in the wrong program, the file type does not have a default set, or the default is not what you want. Specify the program name first instead, as described above. If you want to change the default for that file type permanently, right-click the file in File Explorer, select "Open with", choose the program you want, and check "Always use this app".
Frequently Asked Questions
How do I find the full path to a file?
Open File Explorer, navigate to the file, and click the address bar at the top. The full path will appear. You can also right-click the file, select "Copy as path", and paste it into Command Prompt.
Can I open a file that is on a network drive or external hard drive?
Yes, if the drive is already connected and assigned a letter. Type the drive letter followed by a colon, like E:\filename.txt. If the network drive is not mapped to a letter, you need to map it first using File Explorer or the net use command.
What if I want to open a file but do not know which program to use?
Right-click the file in File Explorer and select "Open with" to see what programs are available. You can also search online for the file extension — for example, ".psd" files are Photoshop files, ".mp4" files are videos.
Does the filename need to include the file extension?
Yes. Command Prompt needs the full filename including the extension, like document.txt or photo.jpg. If you leave off the extension, Command Prompt will not find the file.