Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening file with spaces in Windows via Command Prompt

I want to open a file (particularly video files) in its default program via script. When I come across a file name with spaces, it is taken as several arguments which was no surprise:

  C:\folder>start test space.avi
  The system cannot find the file test.

However, when I surround the file name with quotes:

  C:\folder>start "test space.avi"

instead of opening the file in its default program (VLC), a new Command Prompt window is opened up to the directory of the file.

Opening a file without a space or quotes opens the file in VLC as expected.

How can I get around this?

like image 488
unmuse Avatar asked Dec 03 '12 21:12

unmuse


People also ask

How can open folder with space in CMD?

Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.

How do you handle spaces in CMD?

By adding a caret character ( ^ ) before each space. (This only works in Command Prompt/CMD, and it doesn't seem to work with every command.) By adding a grave accent character ( ` ) before each space.

How do I run a batch file with spaces?

The correct syntax is to use quotation marks in the path. No special escapers are needed to insert a space. For example: start "C:\Program Files (x86)\main.exe"


2 Answers

I suspect start does something special when the first char of the first argument is a quote. The first argument is a window title, and the second is the command/file to open

start "" "test space.avi"

http://ss64.com/nt/start.html

like image 98
glenn jackman Avatar answered Oct 10 '22 06:10

glenn jackman


Just leave off start, and surround the full filename (including any path) with double-quotes. This works fine on my system:

C:\>"test space.avi"
like image 22
Ken White Avatar answered Oct 10 '22 05:10

Ken White