JSI Tip 9581. How can I convert a SFN (Short File SFName) to its' LFN (Long File Name)?

Jerold Schulman

July 21, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted LongFileName.bat to convert a SFN to its' LFN.

The syntax for using LongFileName.bat is:

LongFileName ShortName LongName

Where:

ShortName is the files SFN, like BLANKS~1.DOC.LongName  is a call directed environment variable that will contain the LFN, like Blank Shipping Labels.doc.

LongFileName.bat contains:

@echo offif {%2}=={} @echo Syntax: LongFileName ShortName LongName&goto :EOFif exist "%TEMP%LongFileName.vbs" goto doit@echo set oArgs = Wscript.Arguments>"%TEMP%LongFileName.vbs"@echo wscript.echo LongName(oArgs(0))>>"%TEMP%LongFileName.vbs"@echo.>>"%TEMP%LongFileName.vbs"@echo Function LongName(strFName)>>"%TEMP%LongFileName.vbs"@echo Const ScFSO = "Scripting.FileSystemObject">>"%TEMP%LongFileName.vbs"@echo Const WScSh = "WScript.Shell">>"%TEMP%LongFileName.vbs"@echo.   With WScript.CreateObject(WScSh).CreateShortcut("dummy.lnk")>>"%TEMP%LongFileName.vbs"@echo.     .TargetPath = CreateObject(ScFSO).GetFile(strFName)>>"%TEMP%LongFileName.vbs"@echo.     LongName = .TargetPath>>"%TEMP%LongFileName.vbs"@echo.   End With>>"%TEMP%LongFileName.vbs"@echo End Function>>"%TEMP%LongFileName.vbs":doitif not exist %1 set %2=NONE&goto :EOFset %2=NONEfor /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%LongFileName.vbs" %1') do ( set %2=%%a)



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like