Home » How To » Open Files With Command Prompt: A Complete Guide

Open Files With Command Prompt: A Complete Guide

The command line is a powerful tool in Windows 10/11. Using the Command Prompt, PowerShell, or Windows Terminal, you can open any file you want with a single command.

One of the basic functions of the Command Prompt is creating a file, navigating folders, and opening files. Compared to using File Explorer, the command line makes it quick work to open a file by avoiding the need to navigate through various folders and menus. To open a file using Command Prompt or PowerShell, all you have to do is type the appropriate command and press Enter.

Opening files from the command line is especially useful when creating scripts, opening multiple files at once, working with large files, etc. For example, I use the trick below to open Chrome using Command Prompt.

In this article, I will explain all the necessary commands and usages to open files with Command Prompt on Windows 10/11.

Table of contents:

  1. How to open a file using Command Prompt
  2. How to find a file using Command Prompt
  3. Conclusion

How To Open a File Using Command Prompt

There are three ways you can open files from the Command Prompt window. You can navigate to the folder first and then open the files, open the file directly using the full file path, or open a file with a specific program. I will show all three methods. Each method is useful in a different situation. So, learn and use them as and when needed.

Important note: Though the guide talks about Command Prompt, you can follow the same steps in PowerShell or Windows Terminal.

Open files using Command Prompt by first navigating to the folder

If you know where the file is located, you can navigate to that folder in Command Prompt and then open it. That way, you don’t have to type the full file path whenever you want to open it. This is particularly useful if you are working on multiple files in the same directory.

  1. Open Command Prompt.
  2. Use “cd C:\path\to\folder” to navigate to the folder.
  3. Type “fileName.png” to open the file in Command Prompt.
  4. Close the Command Prompt window.

Steps with more details:

First, open the Command Prompt window. To do that, search for “Command Prompt” in the Start menu and click on the top result. If you want, you can open “Windows Terminal” and then open “Command Prompt” from the title bar.

open command prompt

After opening the Command Prompt window, type “cd C:\path\to\folder” while replacing the dummy path with the real path and press Enter. This will change the directory and take you to the folder you want.

Note: If you are trying to navigate to another drive in command line, like the D drive, you must execute the “DriveLetter:” (without quotes) command where “DriveLetter” is the actual drive letter. For example, you should run “D:” (without quotes) to navigate to the D drive. Once you are in the drive, use the CD command.

Once you are in the directory, type “fileName.png” to open the file. Of course, replace the dummy file with the actual file name and extension.

open file using Command Prompt by first navigating to the folder

As soon as you do that, the file will be opened with the default program. For instance, if you are opening an image, it will be opened in the Photos app unless you set another app as the default photo viewer.

Open files using Command Prompt directly

You open files directly using the Command Prompt. i.e., without navigating to the folder first. This method is useful when you don’t want to change the directory, when opening multiple files in different directories, etc.

  1. Open Command Prompt.
  2. Type “C:\path\to\fileName.png” to open the file in Command Prompt.
  3. Close the Command Prompt window.

Steps with more details:

Open the Command Prompt window by searching for it in the Start menu. Alternatively, press the “Windows key + X” shortcut and select “Terminal.” Next, open Command Prompt from the terminal title bar dropdown menu.

open command prompt

In the Command Prompt window, type the line below with quotes while replacing the dummy file path with the real one. Of course, don’t forget the file extension.

 "C:\path\to\fileName.png"

For example, I’d use the below command line to open an Excel file.

 "D:\WindowsLoop\My Folder\Yearly Commissions.xlsx"

As soon as you do that, the file will be opened in the default program. In my case, it will be the MS Excel application.

open a file using command prompt

Open files with a specific program using Command Prompt

Sometimes, you might want to open a file with a specific program. For example, rather than opening an image file with the default Photos app, you might want to use an alternate program like Photoshop, Quick Picture Viewer, etc. In those cases, you can use the below method.

  1. Open Command Prompt.
  2. Type “C:\path\to\program.exe” C:\path\to\fileName.png” to open the file in Command Prompt with a specific program.
  3. Close the Command Prompt window.

Steps with more details:

Open the Command Prompt window by searching for it in the Start menu. Alternatively, press the “Windows key + X” shortcut and select “Terminal.” Next, open Command Prompt from the terminal title bar dropdown menu.

open command prompt

Next, run the below command with quotes while replacing the program and file paths with real paths.

 "C:\path\to\program.exe" C:\path\to\fileName.png"

For example, I want to open an image with Quick Picture Viewer. So, I use the below command.

 "C:\Program Files (x86)\QuickPictureViewer\quick-picture-viewer.exe" "D:\WindowsLoop\My Image.png"

The file will be opened with the selected application as soon as you execute the command.

open file with a specific program using command prompt

How To Find a File Using Command Prompt

Sometimes, you might want to find the file in Command Prompt before opening it. This is especially true if you want to confirm the file exists before opening it so that you don’t face errors.

Here’s how to find files in Command Prompt:

  1. Open Command Prompt.
  2. Use “cd C:\path\to\folder” to navigate to the folder.
  3. Run the “dir “\search term*” /s” command to search and find the files.
  4. To find a specific file, run the “dir “\fileName.png” /s” command.
  5. Close the Command Prompt window.

Steps with more details:

Open the Command Prompt window by searching for it in the Start menu. Alternatively, press the “Windows key + X” shortcut and select “Terminal.” Next, open Command Prompt from the terminal title bar dropdown menu.

Use the CD command to navigate to the folder of your choice.

 cd "C:\path\to\folder"

In the Command Prompt window, run the below command while replacing “search term” with the actual file name and press the “Enter” button.

 dir "\search term*" /s

If you want to search for a specific file, use the full file name along with the extension. The command looks something like this:

 dir "\fileName.png" /s

As soon as you run the search command, the Command Prompt will scan the directories and sub-directories to find the file. Once found, it will list the full file path in the response.

Quickly Opening Files With Command Prompt — Conclusion

Opening files in Command Prompt is a powerful and effective way to handle your files and save time on regular tasks. I’ve gone over three methods to open files in Command Prompt and explore and find files using various commands. Depending on your use case, follow the method that is useful to you.

Learning how to use the command line to open files is a useful skill to have whether you are a casual user or a professional.

That is all. It is that simple to open a file using Command Prompt.

I hope this simple and easy Windows how-to guide helped you.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top