Results 1 to 9 of 9

Thread: Converting a File path and name to DOS format.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Wales, UK
    Posts
    14

    Converting a File path and name to DOS format.

    Is there any way (in VB5) to take a file path and name taken from a common dialog control and convert it to DOS format?

    e.g. C:\hello\thisislongerthan8letters\file.bas

    would go to

    C:\hello\thisis~1\file.bas
    Neil
    HTML, JavaScript, QBasic and learning VB5

    Mod at http://www.htmlhelpcentral.com

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. 'Make a new project. Add a module. To the form add a command button.
    2.  
    3. 'Code:
    4. 'Add this code to the module:
    5.  
    6. Declare Function GetShortPathName Lib "kernel32" Alias _
    7. "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal _
    8. lpszShortPath As String, ByVal lBuffer As Long) As Long
    9.  
    10. 'Add this code to the form's General Declarations procedure:
    11.  
    12. Public Function GetShortPath(strFileName As String) _
    13. As String
    14. Dim lngRes As Long
    15. Dim strPath As String
    16. strPath = String$(165, 0)
    17. lngRes = GetShortPathName(strFileName, strPath, 164)
    18. GetShortPath = Left$(strPath, lngRes)
    19. End Function
    20.  
    21. 'Add this code to the command button:
    22.  
    23. Private Sub Command1_Click()
    24. Dim StrShortPath As String
    25. StrShortPath = GetShortPath("c:\dir\this is long.doc")
    26. End Sub

    try that...
    -= a peet post =-

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Wales, UK
    Posts
    14
    It doesnt seem to work for me
    Neil
    HTML, JavaScript, QBasic and learning VB5

    Mod at http://www.htmlhelpcentral.com

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    what happens... u get an errormsg ?
    -= a peet post =-

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    oh.. think I see what the problem is.. it's returning "" if the file or directory does not exist.
    I forgot that .. sorry
    -= a peet post =-

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Wales, UK
    Posts
    14
    How can I fix that?
    Neil
    HTML, JavaScript, QBasic and learning VB5

    Mod at http://www.htmlhelpcentral.com

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    hmm.. not sure u need to fix anything, you dont need the short name of a file or dir. that does not exist ?

    Or do you ?
    -= a peet post =-

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Wales, UK
    Posts
    14
    What I want it for is a win32 IDE for QuickBasic. I am currently coding the compiler bit and instead of takling ages to write my own (and I couldn't anyway) I am using bc.exe and link.exe that come with QB. I get the filename from a common dialog control and I use shell to start up the program with all these files in the command line. Now the dos compilers spit out the error if the dir's or file names are longer than 8 characters (perfectly natural, they are in dos) so I need to make sure the file names and paths are dos compliant.

    This has me stumped, any other suggestions?
    Neil
    HTML, JavaScript, QBasic and learning VB5

    Mod at http://www.htmlhelpcentral.com

  9. #9
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    use above code w/

    if shorpathname(strPathName) <> vbnullstring then
    'do stuff here
    else
    'the dir doesn't exist, warn them
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width