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


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 off
if \{%2\}==\{\} @echo Syntax: LongFileName ShortName LongName&goto :EOF
if 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"
:doit
if not exist %1 set %2=NONE&goto :EOF
set %2=NONE
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\LongFileName.vbs" %1') do (
 set %2=%%a
)



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