Link to home
Start Free TrialLog in
Avatar of jana
janaFlag for United States of America

asked on

How to convert a path to short names in windows command prompt

Hi,

We are trying to take a regular path and convert it to "short name".  For example:

The normal path:    

C:\Program Files\AVAST Software\avast\

Convert  it to:

C:\PROGRA~1\AVASTS~1\avast\

We understand fir /x returns the short name of a folder or file, but  we are  trying  to convert specific path.

How can we go about this?
(we use Windows 10)
ASKER CERTIFIED SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

Thank you very much!

We found that in  one of our searched, but didn't work.,  Seeing your example we were missing the quotes.  We just finish testing and  it gave us the short name  of all the path we need  to work with!

Thanx!
You're welcome! Btw, quotes are needed only when there are spaces in the folder or file name, such as the space in Program Files. They're not needed if there are no spaces in the folder/file name. For example, this works fine without the quotes:

shortname.bat c:\Windows\PolicyDefinitions\

Anyway, I'm glad that works for you! Regards, Joe
Avatar of Bill Prew
Bill Prew

And if you don't want another BAT file, you can do the following at a command prompt:

for %F in ("c:\longpathname\longfilename.txt") do @echo %~sF

Open in new window


»bp
Avatar of jana

ASKER

Thanx!