Open file from the command line on Windows

On Mac OS X and GNOME on Linux, there are commands that can be used to open files from the command line in their associated GUI editors: open and gnome-open, respectively. Is there any command like this for Windows?

4

9 Answers

If you are currently in the command prompt and have a file called test.png and , which are located in c:\test you can do the following:

If you are at the directory (so should say c:\test>) just type:

test.png

which would open test in the default png picture editor.

If the files name contains spaces, then simply enclose the file name within " "

 "this image.png"

You can alternatively type:

c:\test\test.png

which will open the file no matter where you currently are.

Finally, you can pass the picture to another program. For example, if you have an image editor called imageedit.exe and it supports opening files through command lines (and if the program is pathed/accessible or you are in it's current directory), you can type the following:

 imageedit c:\test\test.png
4

If it is a registered extension, you can use "start" as in

start WordDoc.doc
5

On Windows command-line explorer "<PATH>" will open the file path with Windows default associated programs. This will also handle all URIs ( http:,https:,ftp: ) and other file protocols defined in Windows Operating System. If the file or protocol is not associated with any program then an Open With dialog will show up. If file is not present then default My Documents folder will open up. It can also open executable files ( EXE, BAT files) and shell namespace paths.

Examples

explorer ""- will open in windows default browser.

explorer "file:///C:\temp\" will open temp directory if present

explorer "file.txt" will open file.txt on the current directory path .i.e. %CD% path

explorer ::{645ff040-5081-101b-9f08-00aa002f954e} will open RecycleBin.

You can refer about explorer's other useful command-line switches here

powershell -c "folder\childfolder\file.txt"

Source:

Simple and versatile.

0

The first parameter of Start is a window title, so if you have a space in the file name, and you type

Start "My File.txt"

you'll get a command line window with "My File.txt" as the title. To get around this use a dummy title,

Start "my title" "My File.txt"

Depending on the file and what application is opened there probably won't be a window to see anyway.

1

If you are in PowerShell (at the PS (current-directory) prompt), and you want to open a file in the current directory, you may try this .\myfile.ext.  If you are in the Command Prompt, you can accomplish the same result by typing

powershell -c .\myfile.ext

(You must include the .\, as PowerShell doesn’t load files from the current location by default.)  Or you can provide a directory name (relative or absolute) if the file isn’t in the current directory.

For the first scenario — if you are in PowerShell — if the filename contains space(s), enclose it in quotes (either kind) and precede it with the & symbol:

PS C:\Users\myusername\Pictures> &".\funny cat.jpg"

(You may add a space after the & for readability, if you prefer readability, and you may use / instead of \.)  I don’t know how to make this work in the second scenario (in which you are running powershell -c from Command Prompt) if the file or directory name contains space(s) — quotes don’t seem to help.

0

This may come a bit late, but the correct command for editing a file name in Windows 7 is "write file_name"

This should open up the default text editor and you should be able to edit the file easily

Edit: It seems to open only Wordpad. For me that was the default text editor.

3

Specific executable with specific file:

Git Bash Script On Windows 10 :


SHORTCUTS_MAIN_START.sh :

 FILE_PATH="C:\DEV\REPO\GIT\AHK03\SHORTCUTS\SHORTCUTS_MAIN.ahk" EXEC_PATH="C:\DEV\REPO\GIT\AHK03\AHK_ROOT\AutoHotkeyU64.exe" $EXEC_PATH $FILE_PATH

This example opens the file denoted by $FILE_PATH with the executable denoted by $EXEC_PATH. If this doesn't work for you, try converting the single slash ( "\" ) into double slashes ( "\\" ) for the paths.

In the Windows command prompt, you can run

edit [file_name]

in order to view batch files/logs/text files etc. This command requires QBASIC.EXE, which is by default present in Windows.

See here for other useful MS-DOS commands.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like