I have scripted CvtLFNSFN.bat to convert a LFN (Long File Name) to a SFN (Short File Name).

NOTE: LFN refers to the file name and extension, NOT to the folder path.

The syntax for using CvtLFNSFN.bat is:


Where LFN can be the LFN or the FQFN (Fully Qualified File Name), and SFN is a call directed environment variable that will contain the SFN.

NOTE: Neither the LFN nor the FQFN has to exist.

CvtLFNSFN.bat contains:

@echo off                              if \{%2\}==\{\} @echo Syntax: CvtLFNSFN LFN SFN&goto :EOF                              setlocal                              set file=%~nx1                              @echo.>"%TEMP%\%file%"                              :loop                              for /f "Tokens=1* Delims=\" %%a in ('dir "%TEMP%\%file%" /X^|find "%file%"') do (                               set line=%%a                              )                              del /q "%TEMP%\%file%"                              for /f "Tokens=1*" %%a in ('@echo %line:~36%') do (                               set sfm=%%a                              )                              endlocal&set %2=%sfm%