tags:

views:

407

answers:

12

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?

+15  A: 

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.

Boris Guéry
can you explain why "c:\PROGRA~1" means the same as "c:\Program Files"?
Shore
Can you be sure that the short name does never change, which would be important for a configuration file?
mghie
It's a Windows short file name (http://www.chami.com/tips/windows/122496W.html). It's an 8.3 filename for backward compatibility.
0xA3
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.
Paulo Santos
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"
0xA3
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"
ChrisF
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~2
Amadiere
@Shore edited the answer, from dir /? command
Boris Guéry
@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.
mghie
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 problematic
spender
@mghie - 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.
ChrisF
+3  A: 

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.

S.Lott
As i said in my response, it's possible to use the short-name notation.
Boris Guéry
@bgy: That's pretty clear -- that's the way SO works. Why are you also making a comment here? Isn't your answer sufficient?
S.Lott
+1  A: 

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

jschoen
A: 

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

Fredrik Mörk
Thanks, and the reason for that downvote would be?
Fredrik Mörk
I got the same treatment, so I've added an upvote to you.
crashmstr
A: 

You could try to use:

C:\PROGRA~1
vobject
A: 
c:\progra~1

On 64-bit windows, possibly

c:\progra~2
spender
wtf? why the markdown?
spender
I got the same treatment.
crashmstr
+1  A: 

You could try using the short file name (probably c:\PROGRA~1), but you really are not telling us much detail.

Another possible option would be to put quotes around the full path, "c:\program files\Path\configfile.ini"

crashmstr
+3  A: 

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.

Steve Cooper
A: 

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

Richard
A: 
Jean
+2  A: 

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.

A. Scagnelli
+1  A: 

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.

harms