Windows path without spaces (with ~1)?

14

4

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

Shane

Posted 2010-08-23T13:38:47.360

Reputation: 2 810

Can't you just use quotation marks so you can leave the spaces in place? e.g., "C:\Program Files" – Uninspired – 2010-12-02T00:56:46.507

Answers

24

You can use for each folder:

DIR /X

BillP3rd

Posted 2010-08-23T13:38:47.360

Reputation: 5 353

1doesnt work on win 10 – AndroidMechanic - Viral Patel – 2017-04-05T11:55:23.233

Doesn't this just show the short name for the file itself but not the folder ? – Chad – 2017-05-02T14:32:50.453

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. – Rockin4Life33 – 2019-08-27T04:24:14.190

2also don't forget dir /x /a for hidden files – Drew LeSueur – 2011-08-05T09:06:25.990

1

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

Srin

Posted 2010-08-23T13:38:47.360

Reputation: 464

Actually the directory above the required directory. – Noumenon – 2017-01-23T03:28:37.547

doesnt work in win 10 – AndroidMechanic - Viral Patel – 2017-04-05T11:55:11.960

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

Julien N

Posted 2010-08-23T13:38:47.360

Reputation: 518