Opening a file in Command Prompt means telling the system which program should read it

Command Prompt does not open files the way your mouse does. When you double-click a document on your desktop, Windows already knows which program handles that file type. In Command Prompt, you have to say both the program name and the file path. The simplest way is to type the program name, a space, and then the full path to the file in quotation marks if the path contains spaces.

For example, to open a text file called notes.txt in Notepad, you would type: notepad "C:\Users\YourName\Documents\notes.txt" and press Enter. Command Prompt passes the file to Notepad, Notepad opens, and the file appears on your screen. The Command Prompt window stays open unless you close it.

The key difference from clicking is that you control which program opens the file. A .txt file normally opens in Notepad, but you could open it in Word, VS Code, or any text editor you have installed. This matters when you want to use a specific program or when Windows has chosen the wrong default.

Key Takeaways

  • The basic syntax is the program name followed by the file path in quotation marks: notepad "C:\path\to\file.txt"
  • Always use quotation marks around the file path if it contains spaces or special characters.
  • You can open files with any program installed on your computer, not just the default one Windows chose.
  • Use the full path starting from C:\ or another drive letter, or use a relative path if you have already navigated to the file's folder.

Finding the correct file path

Before you can open a file in Command Prompt, you need to know where it lives on your computer. The easiest way is to open File Explorer, find the file, right-click it, and select Copy as path. This copies the full path to your clipboard. Then paste it into Command Prompt with Ctrl+V.

If Copy as path is not in your right-click menu, you can navigate to the file's folder in Command Prompt instead. Use the cd command to change directories. For example, cd Documents moves you into the Documents folder. Then type just the filename: notepad notes.txt. Command Prompt will look for the file in the current folder.

You can also see what files are in the current folder by typing dir and pressing Enter. This lists all files and folders, so you can verify the filename is spelled correctly before you try to open it.

Common programs and their command names

Different programs have different command names in Command Prompt. Notepad is notepad, but Word is winword, and Excel is excel. If you are not sure what the command is, the safest approach is to type the program name as it appears in your Start menu, in lowercase, without spaces.

For built-in Windows programs, these are the most common:

  • notepad — opens Notepad, the basic text editor
  • wordpad — opens WordPad, which handles .rtf and .docx files
  • mspaint — opens Paint for image files
  • calc — opens Calculator
  • winword — opens Microsoft Word if installed
  • excel — opens Microsoft Excel if installed

If the program is not in your PATH (a list of folders Command Prompt searches automatically), you will get an error saying the program was not found. In that case, you need to type the full path to the program itself, like "C:\Program Files\MyProgram\myapp.exe" "C:\path\to\file.txt"

Handling file paths with spaces and special characters

File paths with spaces must be wrapped in quotation marks, or Command Prompt will treat each word as a separate instruction. If your file is at C:\Users\John Smith\Documents\my file.txt, you must type: notepad "C:\Users\John Smith\Documents\my file.txt"

Without the quotes, Command Prompt reads "John" as a separate command and fails. The same rule applies to any special characters like hyphens, parentheses, or ampersands in the filename or folder names.

If you are navigating with cd commands, you also need quotes around folder names with spaces. For example: cd "Program Files" moves you into the Program Files folder. Once you are inside that folder, you can type filenames without quotes as long as they do not contain spaces.

Opening files without specifying a program

You can also open a file using just its path, without naming a program first. Type the full path in quotation marks and press Enter: "C:\Users\YourName\Documents\notes.txt" Command Prompt will use whatever program Windows has set as the default for that file type. This is the same as double-clicking the file in File Explorer.

This method is useful when you want the default behavior and do not need to choose a specific program. However, it only works if the file type has a default program assigned. Some file types, like .log or .config files, may not have a default, and Command Prompt will ask you to choose a program or show an error.

Troubleshooting when files will not open

If you type a command and nothing happens, or you see an error, check these things first. The most common mistake is a typo in the file path or program name. Use the dir command to list files in the current folder and verify the exact spelling. Copy and paste the filename instead of typing it by hand.

If you see "is not recognized as an internal or external command", the program is not in your PATH. Either type the full path to the program, or navigate to the folder where the program is installed and run it from there. For programs in Program Files, the full path usually looks like: "C:\Program Files\ProgramName\program.exe"

If the file opens but looks wrong — like a Word document opening in Notepad as gibberish — you used the wrong program. Close it and try again with a program designed for that file type. Word files (.docx) need winword, not notepad. Image files need mspaint or another image viewer.

Using relative paths to save typing

A relative path is shorter because it starts from wherever you are in Command Prompt, not from the C:\ drive. If you navigate to your Documents folder with cd Documents, you can then open a file with just its name: notepad notes.txt instead of the full path.

You can also move up one folder level with cd .. and then down into another folder. For example, if you are in Documents and want to open a file in Downloads, you could type cd ..\Downloads and then notepad filename.txt. This is faster than typing the full path every time, especially if you are opening multiple files in the same folder.

To see where you are right now, type cd with no arguments and press Enter. Command Prompt will print your current location. This helps you understand which relative paths will work.

Frequently Asked Questions

What if the file path has a colon or other special character in the filename?

Wrap the entire path in quotation marks. Colons are allowed in file paths as long as they are not the drive letter (C:, D:, etc.). For example: notepad "C:\Users\YourName\Documents\file: notes.txt" The quotes tell Command Prompt to treat everything inside as a single path, not separate commands.

Can I open a file that is on a network drive or external hard drive?

Yes. Use the drive letter or network path the same way you would for a local folder. For an external drive, it might be D:\ or E:\. For a network drive, use the full path like "\\servername\foldername\filename.txt" Make sure the drive is connected and visible in File Explorer first.

What does it mean if Command Prompt says "Access is denied"?

The file exists, but you do not have permission to open it. This usually happens with system files or files owned by another user. Try running Command Prompt as Administrator by right-clicking the Command Prompt icon and selecting Run as administrator. If the file is owned by another user account, you may need their permission.

Can I open multiple files at once?

Yes. Type the program name followed by multiple file paths: notepad "file1.txt" "file2.txt" "file3.txt" Each file will open in a separate window of the same program. This is faster than opening them one at a time.

Why does my file open and then close when ready?

Some programs close after opening a file if there is an error or if the file format is wrong. Check that you are using the correct program for the file type. If the file is corrupted, the program may not be able to read it. Try opening the file in File Explorer to see if it works there, or try opening it with a different program.