Omar Lujan
New Member
- Joined
- Nov 4, 2008
- Messages
- 12
Hello,
I've been working with the getshortname() API, but have found that it has trouble handling strings that are already in short name format. I used a trim function to work around this. Now I find another problem; the API doesn't change paths with spaces in them. for example:
H:\WCMGMT\WC Prod\Backup2\
should return
H:\WCMGMT\WCPROD~1\Backup2\
Here is the code:
The code works, somewhat. It is able to change
C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705
to
C:\WINDOWS\MICROS~1.NET\FRAMEW~1\V10~1.370
but not
H:\WCMGMT\WC Prod\Backup2\
to
H:\WCMGMT\WCPROD~1\Backup2\
as I mentioned above. Does anyone have any suggestions??
Thanks in advance!
-Omar
I've been working with the getshortname() API, but have found that it has trouble handling strings that are already in short name format. I used a trim function to work around this. Now I find another problem; the API doesn't change paths with spaces in them. for example:
H:\WCMGMT\WC Prod\Backup2\
should return
H:\WCMGMT\WCPROD~1\Backup2\
Here is the code:
Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal longPath As String, ByVal shortPath As String, ByVal shortBufferSize As Long) As Long
Private Sub Test()
Dim longPathName As String
longPathName = "H:\WCMGMT\WC Prod\Backup2\"
'
'Get the size of the string to pass to the string buffer.
Dim longPathLength As Long
longPathLength = Len(longPathName)
'
'A string with a buffer to receive the short path from the api call...
Dim shortPathName As String
shortPathName = Space$(longPathLength)
'
'Will hold the return value of the api call which should be the length.
Dim returnValue As Long
'Now call the function to do the conversion...
returnValue = GetShortPathName(longPathName, shortPathName, longPathLength)
ActiveCell = shortPathName
'If shortpathname is all spaces then change the cell txt back to original file path
ActiveCell = Trim(ActiveCell.Text)
If IsEmpty(ActiveCell) = True Then ActiveCell = longPathName
End Sub
The code works, somewhat. It is able to change
C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705
to
C:\WINDOWS\MICROS~1.NET\FRAMEW~1\V10~1.370
but not
H:\WCMGMT\WC Prod\Backup2\
to
H:\WCMGMT\WCPROD~1\Backup2\
as I mentioned above. Does anyone have any suggestions??
Thanks in advance!
-Omar