Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetShortPathName for folders with foreign characters

Posted on 2006-06-26
3
Medium Priority
?
496 Views
Last Modified: 2013-12-03
I am trying to get the attributes of a folder with foreign characters in it (asian fonts)

I have populated an array of directory names using FindFirstFileW and FindNextFileW
(it confirms that each entry in the array is an existing directory)

I then want to look at the attributes of each directory

    aFolderList = GetFoldersWithForeignCharacters(ReadPath)
   
        For i = 0 To UBound(aFolderList)
           
            Set Current_Folder = Fso.GetFolder(Get_DOS_Path(aFolderList(i)))
            ' the below line doesn't work either
            'Set Current_Folder = Fso.GetFolder(aFolderList(i))
       
            If Current_Folder.Attributes And System Then _
               Current_Folder.Attributes = Current_Folder.Attributes Xor System
        Next

Public Function Get_DOS_Path(sLongName As String) As String

    'return DOS path & File_Name (8.3 compliant)
    Dim sOUT As String, lRet As Long
    sOUT = String(MAX_PATH + 2, 0)
    lRet = GetShortPathName(sLongName, sOUT, MAX_PATH + 1)
    If lRet > 0& Then
        Get_DOS_Path = Left$(sOUT, lRet)
    end if
end function



I am getting a file path not found when I try to assign the current_folder
if I do it with or without the getShortPathName function

Any ideas on how to use the fso.getfolder to accept foreign chracters,
or on how to get GetShortPathName to accept them
or is there another way to read and set the folder attributes?

Thanks,

DT
0
Comment
Question by:dtruong98
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
davidnsc1 earned 1500 total points
ID: 16988374
You really shouldn't use the FileSystemObject.  The GetFileAttributesW and SetFileAttributesW apis will do nicely.
Be sure to use GetShortPathNameW instead of GetShortPathNameA.

In order to use the wide APIs, change all "Byval whatever as String"s in the API declarations to "Byval whatever as Long", and then instead of passing it, say, sLongName, pass it StrPtr(sLongName).

(And FYI, String() also has the faster, non-variant version String$(), but in general, for cases like these, if you're going for speed, it's better to use Space$(), since GetShortPathName adds its own null char anyway)
0
 
LVL 22

Expert Comment

by:danaseaman
ID: 16996935
Try this. If it still does not work there may be a problem in "GetFoldersWithForeignCharacters" filling the array of Unicode names. Will need to see the code to fix it.

Private Declare Function GetFileAttributesW Lib "kernel32" (ByVal lpFilename As Long) As Long
Private Declare Function GetShortPathNameW Lib "kernel32" (ByVal lpszLongPath As Long, ByVal lpszShortPath As Long, ByVal cchBuffer As Long) As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal psString As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Public Function GetFileAttributes(ByVal lpFilename As String) As Long
   GetFileAttributes = GetFileAttributesW(StrPtr(lpFilename))
End Function

Public Function GetShortName(ByVal sLongFileName As String) As String
   Dim lRetVal          As Long
   Dim lPtr             As Long
   Dim lBuff            As Long
   Dim Buffer              As String * 255

   lPtr = StrPtr(sLongFileName)
   lBuff = StrPtr(Buffer)
   If lPtr Then
      lRetVal = GetShortPathNameW(lPtr, lBuff, 255)
      GetShortName = PtrToStrW(lBuff)
   End If
End Function

'Dereference Unicode string pointer
Public Function PtrToStrW(ByVal lpsz As Long) As String
   Dim lLen             As Long
   If lpsz Then
      lLen = lstrlenW(lpsz)
      PtrToStrW = Space$(lLen)
      CopyMemory ByVal StrPtr(PtrToStrW), ByVal lpsz, lLen * 2
   End If
End Function
0
 
LVL 22

Expert Comment

by:danaseaman
ID: 16998949
Hi,
   Just a quick comment. If you are using FindFirstFileW to retrieve files then you already have the attribute of each file via the Win32FD structure as Win32FD.dwAttributes.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question