Skip navigation

JSI Tip 8518. How can I convert a LFN to a SFN?


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:

CvtLFNSFN LFN SFN

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%



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish