Solved

GetShortPathName for folders with foreign characters

Posted on 2006-06-26
3
491 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month4 days, 10 hours left to enroll

636 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