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
Printable View
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
VB Code:
'Make a new project. Add a module. To the form add a command button. 'Code: 'Add this code to the module: Declare Function GetShortPathName Lib "kernel32" Alias _ "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal _ lpszShortPath As String, ByVal lBuffer As Long) As Long 'Add this code to the form's General Declarations procedure: Public Function GetShortPath(strFileName As String) _ As String Dim lngRes As Long Dim strPath As String strPath = String$(165, 0) lngRes = GetShortPathName(strFileName, strPath, 164) GetShortPath = Left$(strPath, lngRes) End Function 'Add this code to the command button: Private Sub Command1_Click() Dim StrShortPath As String StrShortPath = GetShortPath("c:\dir\this is long.doc") End Sub
try that...
It doesnt seem to work for me :(
what happens... u get an errormsg ?
oh.. think I see what the problem is.. it's returning "" if the file or directory does not exist.
I forgot that .. sorry
How can I fix that?
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 ?
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?
use above code w/
if shorpathname(strPathName) <> vbnullstring then
'do stuff here
else
'the dir doesn't exist, warn them