# How to deal with file names that have spaces in Command Prompt



## exad

Quote:


Originally Posted by *pauldovi* 
How do you manupulate files in the Windows Command prompt that have a space in them? Say I want to run "this program.exe". Typing in this program.exe will not work.









I don't really know cuz I haven't ever tried but did you try using % as a space?


----------



## PhillyOverclocker

Spaces do work in command prompt as far as I have have ever used them. What is is you are trying to do?


----------



## pauldovi

Well Windows allows for spaces... so it should be able to manipulate them.

I am using Windows Server 2008 Core, and there is no GUI.


----------



## acruxksa

In Linux you use a \\ in front of the space, but not sure about windows. I always thought windows just handled the spaces. Never really ran into the problem I guess.


----------



## e_dogg

Put the file name in quotes. This should also work for complete file paths too.

"like this.exe"
"c:\\my folder\\like this.exe"


----------



## dr4gon

spaces work just fine in my windows comand prompt for loading up a program that's like pro gram.exe


----------



## Chipp

Quote:


Originally Posted by *e_dogg* 
Put the file name in quotes. This should also work for complete file paths too.

"like this.exe"
"c:my folderlike this.exe"

This has always worked for me, as well.


----------



## kennymester

I know that in html %20 is the code for space. I don't know though if that workd in cmd.


----------



## Cool Matty

%20 does nothing, because as you said, it's HTML. It only works in browsers.

The correct method would be quotes or escaping each space. Command prompt will do this for you if you start typing it out, then hit tab. It'll auto-complete the rest of the name, with quotes or escaped characters if necessary.


----------



## PhillyOverclocker

Yeah, HTML and other markup languages are not real languages, they are only a way of telling a page how to be formatted.


----------



## The Hundred Gunner

Enclosing the string in quotes works. The reason this is required is because terminals are designed to stop reading input at the first white space (tab, space, new line).

So to copy a file called Stupid File.zip to Stupid File2.zip, you would do:

Code:



Code:


cp "Stupid File.zip" "Stupid File2.zip"

To change to a directory, such as Program Files:

Code:



Code:


cd "Program Files"

See, Linux makes you smart


----------



## pauldovi

Quote:


Originally Posted by *The Hundred Gunner* 
Enclosing the string in quotes works. The reason this is required is because terminals are designed to stop reading input at the first white space (tab, space, new line).

So to copy a file called Stupid File.zip to Stupid File2.zip, you would do:

Code:



Code:


cp "Stupid File.zip" "Stupid File2.zip"

To change to a directory, such as Program Files:

Code:



Code:


cd "Program Files"

See, Linux makes you smart









That was the first method that came to mind when I ran into the problem. Unfortunately it did not work.

For some reason just typing File Name.exe worked... It didn't the first time I tried.


----------



## The Hundred Gunner

Quote:


Originally Posted by *pauldovi* 
That was the first method that came to mind when I ran into the problem. Unfortunately it did not work.

For some reason just typing File Name.exe worked... It didn't the first time I tried.









Interesting.


----------



## ghell

Quote:


Originally Posted by *pauldovi* 
Say I want to run "this program.exe".

I like how the answer was in his original post. If you want to run "this program.exe" then you run "this program.exe" with the quotes. The quotes must start at the start of the path and end at the end of the file extention. For example

Code:



Code:


> "my images/my viewer.exe" image1.jpg image2.jpg

will run "my images/my viewer.exe" with arguments "image1.jpg", "image2.jpg" but

Code:



Code:


> my images/my viewer.exe image1.jpg image2.jpg

will try to run my.exe (or my.com or my.bat, any of the automatic extensions) with the arguments "http://www.overclock.net/images/my", "viewer.exe", "image1.jpg", "image2.jpg".

You cannot use

Code:



Code:


> my images/"my viewer.exe"

or

Code:



Code:


> "my images/my viewer.exe image1.jpg image2.jpg"

Quote:


Originally Posted by *PhillyOverclocker* 
Yeah, HTML and other markup languages are not real languages, they are only a way of telling a page how to be formatted.

Very true (assuming by "real language" you mean something like an imperative language or a functional language), though %20 is nothing to do with HTML at all. It is part of the encoding used in URIs. + is an alternative in the URI but it also nothing to do with the HTML. 0x20 is the hexidecimal value of the ascii character for space (32). In other languages other notations are used, such as \\20. In html, it would be & #32;

On Linux you can generally either use quotation marks just as you would in windows or you can escape spaces with a \\. It depends on the shell.


----------



## tope

Enclose the filename with double qoute. Example: c:\"tope Installer"

i use this in changing my folder attribute.

in command prompt (cmd) , i type in
c:\attrib -s -r -h "tope Installer"

Note: tope installer is a folder name. Hope this help.


----------



## mastesz13

open CMD,

if the file name is: "my example.exe"

type \*example.exe

* = means all with the same this "last charaters" and/or "file extension"

unless your naming is "my one example.exe" and you have another file name with "my 2nd example.exe"

then you are doomed...........


----------



## Plan9

so much miss information here.

Firstly %20 isn't even HTML, it's URL encoding. It's not part of the HTML spec what so ever.
Next, you don't need double slashes within quotes (eg "c:\path to file\" is valid)
Finally, be careful about using spaces (even within quotes) as parameters as they can play havoc with some programs.


----------

