Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Long File Names to 8.3 standard 1

Status
Not open for further replies.

djhawthorn

Technical User
Mar 4, 2002
641
AU
Does anyone know of a function that will convert a long file name / path to the DOS 8.3 standard?

Like

C:\Program Files\Symantec\Norton AntiVirus
becomes
C:\Progra~1\Symantec\Norton~1


[auto] MCSE NT4/W2K
 
If the file exists (and it really has to, or else there is no mapping between a short and a long name) and you can get at it (not off on some disconnected share)... you can do this via the FSO:
Code:
Option Explicit
Dim objFSO, objFile1, objFile2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = _
  objFSO.GetFile("C:\Program Files\Internet Explorer\iexplore.exe")
Set objFile2 = _
  objFSO.GetFile("C:\Windows\Coffee Bean.bmp")

MsgBox _
    "Path 1: " & objFile1.ShortPath & vbNewLine _
  & "Name 1: " & objFile1.ShortName & vbNewLine & vbNewLine _
  & "Path 2: " & objFile2.ShortPath & vbNewLine _
  & "Name 2: " & objFile2.ShortName

Set objFile2 = Nothing
Set objFile1 = Nothing
Set objFSO = Nothing
For a file that doesn't exist yet this doesn't work. Since the LFN for the file isn't in the directory yet, there is no place for the lfn<->sfn mapping to be looked up. The best you can do then is just guess to create a short name, by truncating the nodes of the path and name and sticking in &quot;~1&quot; before the extension, etc.

Hope this helps.
 
Sweet, thank you.
The file exists, and there should be no problem there. Again, thank you. Saved me a lot of searching.

[auto] MCSE NT4/W2K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top