How To Run File Names With Spaces Through Command Line
There are several ways to open or run a file in Windows. You can double-click the file to open it or use the Run command box. You can also use command prompt to open the file. Sometimes it happens that when we manually enter the full path and filename in command prompt, the file doesn’t open or the program doesn’t run.
Usually when we want to open a file in another program (which Windows recognizes), we use the “start” command before the file path and filename to open the file. Here is the syntax of opening a text file:
But when it comes to filenames with spaces, Windows will only take the first word and search for that name. And if it doesn’t find the filename, it will give the following error:
I have been double quote at the start and end of the filename to open the file.
C:\>start "sample text file.txt"
But sometimes this doesn’t work. Windows will still take the first word i.e., sample as filename and search for it in the specified folder path.
You can also try out the following syntax which I have used successfully to open files through command line:
C:\>start "sample text file".txt
If one option doesn’t work, you can try out the next one and most probably one of the options discussed above will work. I’m not sure why but this is Windows behavior. Different versions of DOS interpret filenames differently and this causes confusion on how to write the correct syntax of filenames with spaces.