Shell - Get short file names for environment variable

M

Markus Eßmayr

Hello,

I have a batch file something like that:

@echo off
set SOMEIMPORTANTFILE=C:\Program Files\Some Directory With Spaces\file.dat
app1.exe "%SOMEIMPORTANTFILE%"
app2.exe "%SOMEIMPORTANTFILE%"
app3.exe "%SOMEIMPORTANTFILE%"

Now I also should add to call another application, which in no case supports
spaces in file names.

Is there a way similar to using %~s1 for converting %1 to a short file name?

Thanks!
Max
 
P

Pegasus \(MVP\)

Markus Eßmayr said:
Hello,

I have a batch file something like that:

@echo off
set SOMEIMPORTANTFILE=C:\Program Files\Some Directory With Spaces\file.dat
app1.exe "%SOMEIMPORTANTFILE%"
app2.exe "%SOMEIMPORTANTFILE%"
app3.exe "%SOMEIMPORTANTFILE%"

Now I also should add to call another application, which in no case
supports spaces in file names.

Is there a way similar to using %~s1 for converting %1 to a short file
name?

Thanks!
Max

You could use this little batch file:
@echo off
set SomeImportantFolder=c:\Program Files\Microsoft Office
pushd "%SomeImportantFolder%"
echo Q > "%temp%\debug.scr%"
debug < "%temp%\debug.scr%" > nul
set wd=%cd%
echo The 8.3 path is %wd%
popd
 
M

Markus Eßmayr

Thanks very much for you fast answer!
Could you please explain, what you are doing here?

Thanks!
 
P

Pegasus \(MVP\)

I thought you might ask . . .

*** pushd "%SomeImportantFolder%"
This is a combined drive & directory change command
that remembers to original drive & directory.

*** echo Q > "%temp%\debug.scr%"
This writes the letter Q (for Quit) into a script file which
I will use in the next command.

*** debug < "%temp%\debug.scr%" > nul
This launches debug.exe for a very brief session. The
sneaky part is that debug.exe is in essence a 16-bit
program. When you launch a 16-bit program then
your current folder name reverts to the 8.3 format.
Any 16-bit application will do.

*** set wd=%cd%
This picks up the current folder name which is now in
8.3 format.

*** popd
This returns you to the original folder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top