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

14

97

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?

Isonomy answered 21/5, 2009 at 11:54 Comment(0)
M
149

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.

Miquelmiquela answered 21/5, 2009 at 11:56 Comment(13)
can you explain why "c:\PROGRA~1" means the same as "c:\Program Files"?Isonomy
Can you be sure that the short name does never change, which would be important for a configuration file?Resee
It's a Windows short file name (chami.com/tips/windows/122496W.html). It's an 8.3 filename for backward compatibility.Pede
The "C:\PROGRA~1" is the way the Windows converts long names, i.e. names greater than the old MS-DOS 8.3 names. You can use the command DIR /X at the command prompt to see the shor name versions of your folders and files.Winburn
The short name might be different from your example, e.g. if you also have a folder named C:\ProgramFiles (without space) or alike you might get C:\PROGRA~2 for "C:\Program Files"Pede
It's the same because ultimately Windows still uses the old 8.3 character name format. "Program Files" is an alias of "PROGRA~1". If you had another directory called "Progress Storage" that would have the short name "PROGRA~2"Morgen
Compatibility with old systems / applications that use the 8.3 filename from the days of MS DOS etc. PROGRA~1 is the first instance of a folder with the first 6 letters "Progra". If you had another folder in the same place called "Program Metadata" - that would be PROGRA~2Rearm
@ChrisF: If only I could downvote your comment, I would. Where do you get the idea that "Windows still uses the old 8.3 character name format"? On the contrary, file systems can be configured to not use it at all.Resee
It's really unlikely to move, because these folders are the first ones to be created when windows is installed. However, in the case of windows being installed to a HD that already has a folder c:\programmable, this might be problematicUnwished
@Resee - all right maybe "use" was too strong a term. The format still available and Windows recognises it so in that sense it "uses" it. I would like to think that if you took it away Windows would still work, but I have the sneaking suspicion that there's still some old code that doesn't recognise long names lurking in the depths of the operating system.Morgen
Thank you for the tip. I was going crazy as I didn't know why it said the location didn't exist for me. What helped me was putting quotes around it.Lumpfish
@Resee I tried the following today under Windows 10, and it still "works": ein-eike.de/2014/11/25/dreckstool-windows-dateisystem Parts of Windows use 8.3 file names by default.Tetartohedral
@Eike: Netter Artikel. However, as I wrote some 12 years ago, this behavior can (and probably should) be disabled. Run "fsutil behavior set disable8dot3 1" in an elevated prompt, restart your system and rerun your test.Resee
T
53

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"
Taxiway answered 28/8, 2017 at 16:46 Comment(0)
C
33

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)%

:

Ceria answered 20/4, 2017 at 12:29 Comment(3)
Avoid doing this because there is no guarantee that they will have been abbreviated to ~1 and ~2 respectively. If someone has installed windows onto a system that already had a folder called, for example, "C:\Programmers", then that would take up the short name "C:\PROGRA~1" so "C:\Program Files" would be "C:\PROGRA~2", etc.Australia
Yes, maybe, but it will work in most of cases. I think the ideal answer would be the highlighted one above, which was answered by lit. Thanks for your inputs anyways.Ceria
Thanks for the solution.Preconception
R
7

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.

Rapeseed answered 21/5, 2009 at 12:34 Comment(0)
V
6

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.

Velamen answered 21/5, 2009 at 12:1 Comment(0)
E
6

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.

Erythrocytometer answered 21/5, 2009 at 12:14 Comment(1)
Using the variables is the correct way. Just because the executable is in a directory will not cause that directory to be the current working directory. The executable will have to do something before a relative directory can be used.Taxiway
A
3

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".

Anglicize answered 21/5, 2009 at 12:1 Comment(1)
This is actually useful when sub-directories are to be short named as well. You can change the dir from C:\ --> C:\sub-dir\ to get more "Short Names".Stefaniestefano
A
2

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.

Adamek answered 21/5, 2009 at 11:57 Comment(2)
As i said in my response, it's possible to use the short-name notation.Nacre
@bgy: That's pretty clear -- that's the way SO works. Why are you also making a comment here? Isn't your answer sufficient?Adamek
V
1

You could try to use:

C:\PROGRA~1
V answered 21/5, 2009 at 11:57 Comment(0)
U
1

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.

Unclean answered 4/4, 2017 at 6:23 Comment(3)
There should be no need to go to links, symbolic or otherwise. It is unlikely that this would resolve the underlying problem.Taxiway
It DOES solve my problems with python, scipy and theano installations. In fact it was definitely the easiest and most safe option (not to say the only). Since the question states nothing about the program, it can indeed be a suitable answer.Reglet
I am glad you have a solution for your problems. I hope that omg is not trying to use a poorly written program that does not handle space and other special characters in pathnames. I am sorry you did, but I never had problems with Python.Taxiway
F
1

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.
Finial answered 9/9, 2018 at 23:39 Comment(0)
I
0

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

Inevitable answered 21/5, 2009 at 11:57 Comment(0)
G
-3

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

Gynaecology answered 21/5, 2009 at 11:57 Comment(2)
The "shortname" might well be incorrect or not even supported on the file system. This answer should be deleted.Taxiway
@Taxiway I merely suggest to use the generated short name, not that is should be hard coded. It may be that the short name mechanism is not available on all platforms where .NET runs these days, but keep in mind that the answer is nine years old. The answer that you provided is a good one, but you could really work on your attitude towards others. That said, this answer provides no value here, so it will eventually be deleted.Gisela
W
-3

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.

Worn answered 12/3, 2016 at 15:48 Comment(1)
This is, to be honest, a very bad and silly answer. Creating a new directory for one file/application? And what if he cannot control where the file is located??Wheelbarrow

© 2022 - 2024 — McMap. All rights reserved.