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?
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"
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
It is a well known problem (at least for me :-)
You will have to use a short name format in your CMD
script.
To find out a short name for a particular file do the following:
- Open a
CMD
window pointing to the file's folder.
- Run the command:
$> dir /X
- In the middle column you will see a short name for the file of interest. In your particular case it will be something like: TESTSP~1.AVI
- Use this bare name in your script.
Hope, it helps
Adding the initial "" as Glen indicated ensures CMD continues and does not enter wait mode. This is particularly important in a batch file.
In summary:
1- Open file and wait for user to close it before proceeding to next command
start "" "test space.avi"
2- Open file and continue to next command (without waiting)
start "" "test space.avi"
Depending on your need you might opt for 1 or 2.