How do I specify C:\Program Files without a space in it for programs that can't handle spaces in file paths?

Windows

Windows Problem Overview


A configuration file needs position of another file,

but that file is located in "C:\Program Files",

and the path with space in it is not recognized,

Is there another way to specify the location without space in it?

Windows Solutions


Solution 1 - Windows

you should be able to use

  • "c:\Program Files" (note the quotes)

  • c:\PROGRA~1 (the short name notation)

Try c:\> dir /x (in dos shell)

> This displays the short names > generated for non-8dot3 file names. > The format is that of /N with the > short name inserted before the long > name. If no short name is present, > blanks are displayed in its place.

Solution 2 - Windows

Never hardcode this location. Use the environment variables %ProgramFiles% or %ProgramFiles(x86)%.

When specifying these, always quote because Microsoft may have put spaces or other special characters in them.

"%ProgramFiles%\theapp\app.exe"
"%ProgramFiles(x86)%\theapp\app.exe"

In addition, the directory might be expressed in a language you do not know. http://www.samlogic.net/articles/program-files-folder-different-languages.htm

>set|findstr /i /r ".*program.*="
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files

Use these commands to find the values on a machine. DO NOT hardcode them into a program or .bat or .cmd file script. Use the variable.

set | findstr /R "^Program"
set | findstr /R "^Common"

Solution 3 - Windows

Use the following notations:

  • For "C:\Program Files", use "C:\PROGRA~1"
  • For "C:\Program Files (x86)", use "C:\PROGRA~2"

Thanks @lit for your ideal answer in below comment:

> Use the environment variables %ProgramFiles% and %ProgramFiles(x86)%

:

Solution 4 - Windows

I think the reason those suggesting using the C:\PROGRA~1 name have received downvotes is because those names are seen as a legacy feature of Windows best forgotten, which may also be unstable, at least between different installations, although probably not on the same machine.

Also, as someone pointed out in a comment to another answer, Windows can be configured not to have the 8.3 legacy names in the filesystem at all.

Solution 5 - Windows

The Windows shell (assuming you're using CMD.exe) uses %ProgramFiles% to point to the Program Files folder, no matter where it is. Since the default Windows file opener accounts for environment variables like this, if the program was well-written, it should support this.

Also, it could be worth using relative addresses. If the program you're using is installed correctly, it should already be in the Program Files folder, so you could just refer to the configuration file as .\config_file.txt if its in the same directory as the program, or ..\other_program\config_file.txt if its in a directory different than the other program. This would apply not only on Windows but on almost every modern operating system, and will work properly if you have the "Start In" box properly set, or you run it directly from its folder.

Solution 6 - Windows

There should be a way to use the full c:\program files path directly. Often, it involves encapulating the string in quotes. For instance, on the windows command line;

c:\program files\Internet Explorer\iexplore.exe 

will not start Internet Explorer, but

"c:\program files\Internet Explorer\iexplore.exe" 

will.

Solution 7 - Windows

No.

Sometimes you can quote the filename.

"C:\Program Files\Something"

Some programs will tolerate the quotes. Since you didn't provide any specific program, it's impossible to tell if quotes will work for you.

Solution 8 - Windows

I think that the other posts have answered the question, but just some interesting for your information (from the command prompt):

dir c:\ /ad /x

This will provide a listing of only directories and also provide their "Short names".

Solution 9 - Windows

You could try to use:

C:\PROGRA~1

Solution 10 - Windows

As an alternative to the other answers, you can try symbolic links.

Create the symbolic link first and install the application based on the link. (Depending on the case, this may be way easier to do, for instance when the application has n mentions of the target folder throughout its code)

A symbolic link will create something similar to a shortcut to a folder, but seen as an actual folder by other applications.

This is how you do it:

  • Run cmd as administrator
  • User this command: mklink /D "C:\LinkToProgramFiles" "C:\Program Files"

And then, you start using "C:\LinkToProgramFiles" in the applications that can't handle spaces. (This link can be seen in Windows Explorer as a folder with the symbol of a shortcut)


Be very careful not to create circular links if you start playing too much with this.

Solution 11 - Windows

Try surrounding the path in quotes. i.e "C:\Program Files\Appname\config.file"

Solution 12 - Windows

You can use the following methods to specify C:\Program Files without a space in it for programs that can't handle spaces in file paths:

'Path to Continuum Reports Subdirectory - Note use DOS equivalent (no spaces)
RepPath = "c:\progra~1\continuum_reports\" or
RepPath = C:\Program Files\Continuum_Reports  'si es para 64 bits.

' Path to Continuum Reports Subdirectory - Note use DOS equivalent (no spaces)
RepPath = "c:\progra~2\continuum_reports\" 'or
RepPath = C:\Program Files (x86)\Continuum_Reports  'si es para 32 bits.

Solution 13 - Windows

Either use the generated short name (C:\Progra~1) or surround the path with quotation marks.

Solution 14 - Windows

You can just create a folder ProgramFiles at local D or local C to install those apps that can be install to a folder name which has a SPACES / Characters on it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionomgView Question on Stackoverflow
Solution 1 - WindowsBoris GuéryView Answer on Stackoverflow
Solution 2 - WindowslitView Answer on Stackoverflow
Solution 3 - WindowsMrDEVView Answer on Stackoverflow
Solution 4 - WindowsharmsView Answer on Stackoverflow
Solution 5 - WindowsAndrew ScagnelliView Answer on Stackoverflow
Solution 6 - WindowsSteve CooperView Answer on Stackoverflow
Solution 7 - WindowsS.LottView Answer on Stackoverflow
Solution 8 - WindowsRichardView Answer on Stackoverflow
Solution 9 - WindowsvobjectView Answer on Stackoverflow
Solution 10 - WindowsDaniel MöllerView Answer on Stackoverflow
Solution 11 - WindowsJacob SchoenView Answer on Stackoverflow
Solution 12 - WindowsdyeView Answer on Stackoverflow
Solution 13 - WindowsFredrik MörkView Answer on Stackoverflow
Solution 14 - WindowsInfinityView Answer on Stackoverflow