9

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?

unmuse
  • 677
  • 2
  • 9
  • 21

4 Answers4

21

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

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
17

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"
Ken White
  • 123,280
  • 14
  • 225
  • 444
3

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:

  1. Open a CMD window pointing to the file's folder.
  2. Run the command: $> dir /X
  3. 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
  4. Use this bare name in your script.

Hope, it helps

Tony Rad
  • 2,479
  • 20
  • 32
Avdej
  • 39
  • 1
  • Um, no you don't. See my answer. – Ken White Dec 03 '12 at 21:37
  • In a general case (which I had in mind) you have to. Unless you want to launch a _GUI application_ and thus don't need to use **start** command at all. – Avdej Dec 04 '12 at 23:50
  • The question specifically asked about using the default program, and most of them (if not all - I haven't found any that failed yet) launch just fine without `start` using a long filename that's quoted. Do you have a specific format (that has a registered default handler) in mind that doesn't work? If it fails to work, it's the program's fault. Windows will pass it the long filename properly, and if the receiving program doesn't use it properly you should replace the receiving program; long filenames have been supported for 17+ years now. – Ken White Dec 04 '12 at 23:53
1

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.

Issam A.
  • 19
  • 3