|
-
October 18th, 1999, 01:09 PM
#1
Quick/Fast/Urgent: How to get DOS path
How do I get the ms dos path for any given path? It would be perfect if I could pass a function a string for the long path, and it would return the dos path.
I swear I saw this before, but couldn't find it. I hope I wasn't dreaming!
-
October 19th, 1999, 02:15 AM
#2
Re: Quick/Fast/Urgent: How to get DOS path
there is a GetShortPathname API
-
October 19th, 1999, 03:00 AM
#3
Re: Quick/Fast/Urgent: How to get DOS path
here is a complete sample with a callable function:
option Explicit
private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (byval lpszLongPath as string, byval lpszShortPath as string, byval cchBuffer as Long) as Long
private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" _
(byval dwFlags as Long, lpSource as Any, _
byval dwMessageId as Long, byval dwLanguageId as Long, _
byval lpBuffer as string, byval nSize as Long, _
Arguments as Long) as Long
private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
private Sub Command1_Click()
MsgBox gsp("c:\programme\microsoft visual Studio")
End Sub
Function gsp(byval longpath as string) as string
Dim lResult as Long
Dim sp as string * 255
lResult = GetShortPathName(longpath, sp, len(sp))
If lResult > 0 then
gsp = Left(sp, lResult)
else
Dim strbuffer as string * 255
FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, byval 0, Err.LastDllError, _
0, strbuffer, len(strbuffer), 0
Err.Raise Number:=vbObjectError + 1001, _
Description:=strbuffer
End If
End Function
-
October 19th, 1999, 07:00 AM
#4
Re: Quick/Fast/Urgent: How to get DOS path
Lothar, just a little hint for your format message:
add FORMAT_MESSAGE_IGNORE_INSERTS as constant, else VB will crash with certain errors (eg. error 129 will cause one) (error that accept inserts (%1, %2, etc, as in sprinf in C)
Crazy D @ Work :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|