|
-
Jun 4th, 2000, 01:07 PM
#1
Thread Starter
New Member
-
Jun 4th, 2000, 04:50 PM
#2
I dont understand why you dont use the API 
Use the DIR function to check if it is the same dir as you are looking for, here is an example.
With api and without
Code:
Option Explicit
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Function GetShortPath(ByVal sLongPath As String) As String
Dim sBuffer As String
Dim lRet As Long
sBuffer = Space$(255)
lRet = GetShortPathName(sLongPath, sBuffer, Len(sBuffer))
If lRet <> 0 Then
GetShortPath = Left$(sBuffer, lRet)
End If
End Function
Public Function GetShortPathWOApi(ByVal sLongPath As String)
Dim sTemp As String
Dim lStart As Long
Dim lTiCounter As Long
Dim bAddedSlash As Boolean
lStart = 1
If Not Right$(sLongPath, Len(sLongPath) - 1) = "\" Then 'Add \ to end
sLongPath = sLongPath & "\"
bAddedSlash = True
End If
Do Until InStr(lStart, sLongPath, "\") = 0 'Do until there are no more slashes
sTemp = Mid(sLongPath, lStart, InStr(lStart, sLongPath, "\") - lStart) 'Get the dir
If Len(sTemp) > 8 Or (Len(sTemp) <> Len(Replace(sTemp, " ", ""))) Then 'If it is bigger then 8chars
'Or path contains one or more spaces
sTemp = Replace(sTemp, " ", "")
sTemp = Left$(sTemp, 6)
lTiCounter = 1 'Do until the short name of the dir is the same as the long name
Do Until Dir(Mid(sLongPath, 1, InStr(lStart - 1, sLongPath, "\")) & sTemp & "~" & lTiCounter, vbDirectory) = _
Dir(Mid(sLongPath, 1, InStr(lStart, sLongPath, "\") - 1), vbDirectory)
lTiCounter = lTiCounter + 1
Loop
sTemp = sTemp & "~" & lTiCounter 'Found the long name
End If
GetShortPathWOApi = GetShortPathWOApi & sTemp & "\"
lStart = InStr(lStart, sLongPath, "\") + 1
Loop
If bAddedSlash Then
'Remove slash
GetShortPathWOApi = Left$(GetShortPathWOApi, Len(GetShortPathWOApi) - 1)
End If
If Dir$(GetShortPathWOApi, vbDirectory) = "" Then
'Doesn't exists
GetShortPathWOApi = ""
End If
End Function
Private Sub Form_Load()
MsgBox GetShortPath("C:\My Music")
MsgBox GetShortPathWOApi("C:\My Music")
End Sub
PS Without the api you cant detetect all path's, some paths are giving really odd short names. I made 14 paths called "12345678 (1-14)" and "C:\test\12345678 11" has a shortpath of "C:\test\12A4A6~1"
[Edited by Azzmodan on 06-05-2000 at 11:59 AM]
-
Jun 4th, 2000, 04:57 PM
#3
PowerPoster
Look!
I just come out something like this & hope it make sense to you. 
Code:
Private Sub Form_Load()
Dim longName$
Dim shortName$
Dim fCnt&
Dim itm$
Dim fArray() As Integer
longName = "My Document"
shortName = Mid(LCase(Replace(longName, Chr(32), "")), 1, 6)
itm = Dir(App.Path & "\" & shortName & "*.txt", vbNormal)
fCnt = 0
Do Until itm = vbNullString
DoEvents
ReDim Preserve fArray(fCnt)
fArray(fCnt) = CInt(Mid(itm, 8, 1))
itm = Dir()
fCnt = fCnt + 1
Loop
'Get the largest value for ~#
itm = 1
For fCnt = 0 To UBound(fArray()) - 1
If fArray(fCnt) < fArray(fCnt + 1) Then
If CInt(itm) < fArray(fCnt + 1) Then itm = fArray(fCnt + 1)
End If
Next
Debug.Print "Final Shortname for " & longName & " = " & shortName & "~" & itm + 1&; ".txt"
End Sub
-
Jun 4th, 2000, 09:30 PM
#4
Thread Starter
New Member
Originally posted by Azzmodan
Code:
'PS Without the api you cant detetect all path's, some paths are giving really odd short names. I made 14 paths called "12345678 (1-14)" and "C:\test\12345678 11" has a shortpath of "C:\test\12A4A6~1"
[Edited by Azzmodan on 06-05-2000 at 11:59 AM]
After looking at this, I assume the GetShorthPath API is better than w/o API huh. Thanks for looking at this post and helping out guys!
PiKaPrO
=======
PiKa ProGraMMeR © 2000
[email protected] No SPAMMERS!
MSVB6.0 PRO SP3 Detected.
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
|