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?
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.
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.
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"
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
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With