Dos File Names

  • 19 years ago

    I need to know if there is any way to change the directory names and such to the dos names  Example: instead of "\Program Files\" I need "\Progra~1\"  I'm using a dir box and a file box.  I take the dir and file name and put into a string, then I pass the string on to a parameter of an executable I'm "Shell"ing from VB. I could really use some help please.  Thanks.

  • 19 years ago

    Well here's what I'd do...


    Break up each directory seperately.  Something like this (I'm coding it now so I hope there aren't errors):


    Dim sPath as string
    Dim sTemp as string
    Dim sNewPath as String
    Dim sExt as string


    sNewPath = left(sPath,3)
    sPath = right(sPath,len(sPath)-3)  'Gets rid of root.  i.e. "C:\"
    Do until instr(1,sPath,"\",1) = 0
     sTemp = left(sPath,instr(1,sPath,"\",1)-1)
     sPath = right(sPath,len(sPath)-len(sTemp)-1)
     If len(sTemp) > 8 Then
        sTemp = left(sTemp,6) & "~1"
     End If
     sNewPath = sNewPath & sTemp & "\"
    Loop
    'Now, sPath should just be your file name
    sExt = right(sPath,4) 'as long as the extension is 3 characters
    sPath = left(sPath,len(sPath)-len(sExt))
    If len(sPath) > 8 then
      sPath = left(sPath,6) & "~1"
    End IF
    sNewPath = sNewPath & sPath & sExt


    I hope that works for you.  The only way this won't work is if two directorys or filenames have the same first six characters and you are trying to access the second one.  Anyway, good luck.

  • 19 years ago

    Alternatively, use the GetShortPathName API:


    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth