16

I want to include the path to a library in the Program Files directory, but I need to do this without spaces. I know that Windows uses a convention that shortens names like Program Files becomes PROGRA~1. How can I find these shortened names for an arbitrary directory?

(Apologies if this has already been asked but I couldn't find it.)

1
  • Can't you just use quotation marks so you can leave the spaces in place? e.g., "C:\Program Files"
    – Uninspired
    Dec 2 '10 at 0:56
27

You can use for each folder:

DIR /X
6
  • 2
    also don't forget dir /x /a for hidden files Aug 5 '11 at 9:06
  • 1
    doesnt work on win 10 Apr 5 '17 at 11:55
  • Doesn't this just show the short name for the file itself but not the folder ?
    – Ivan
    May 2 '17 at 14:32
  • It will work on Windows 10. I used Powershell and was in my home directory, which has a space between my first and last name. I ran DIR/X .. and it spit out my shortened directory(s) I needed to see. Aug 27 '19 at 4:24
  • For me PowerShell didn't work in Windows 10, it gives me an error about being unable to find the C:\X directory. However, it works in good ol' cmd for me.
    – FWDekker
    Dec 8 '20 at 13:41
1

in cmd, go to required directory and type dir/x to see the shortened name for your required folder

2
1

There is a better way to reference the Program Files folder : use the %PROGRAMFILES% variable. And there is no spaces in it :).
For instance : %PROGRAMFILES%\MyLib\MyLib.dll

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.