Anybody know how to go to the ms-dos filename from a known long filename?
Printable View
Anybody know how to go to the ms-dos filename from a known long filename?
If the File is unique, ie the only one of that name, then
can't u just truncate the FileName and append "~1.txt"
(or what ever the file extension is)?
If ur just concerned with converting a FileName to DosName then:
VB Code:
Private Sub Form_Load() MsgBox Get_DosFileName("C:\MyFolder\Longfilename.doc") End Sub Private Function Get_DosFileName(sPath As String) As String Dim sFile As String 'File Name Dim sExt As String 'File extension sFile = Mid$(sPath, InStrRev(sPath, "\") + 1, InStrRev(sPath, ".") - InStrRev(sPath, "\") - 1) sExt = Right$(sPath, Len(sPath) - InStrRev(sPath, ".")) Get_DosFileName = Left$(sFile, 6) & "~1." & sExt End Function
Muck around with this. You should get it.VB Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long Public Function GetShortPath(strFileName As String) As String 'KPD-Team 1999 'URL: [url]http://www.allapi.net/[/url] 'E-Mail: [email][email protected][/email] Dim lngRes As Long, strPath As String 'Create a buffer strPath = String$(165, 0) 'retrieve the short pathname lngRes = GetShortPathName(strFileName, strPath, 164) 'remove all unnecessary chr$(0)'s GetShortPath = Left$(strPath, lngRes) End Function Private Sub Form_Load() MsgBox GetShortPath("c:\Program Files\") End Sub