r4qm4n said:
Some code below as requested by Karl to demonstrate the problem.
Yeah, but it doesn't really. To repeat, here's what I asked...
What you've shown is a filename typed into the VB IDE. Presumably, that's
not how you're attempting to do it, right? Maybe using a Dir() loop,
instead?
That said, your reference to the page with Polish characters triggered
enough of a hint to see what's probably going on here. The filenames are
composed with Unicode characters, it seems. For example, if I name a file
using the Polish alphabet (aabccdeefghijkllmnnóprsstuwyzzz.txt), I get the
following AscW character codes:
97
261
98
99
263
100
101
281
102
103
104
105
106
107
108
322
109
110
324
243
112
114
115
347
116
117
119
121
122
378
380
46
116
120
116
0
But I only get those if I use Unicode API calls. While VB strings are
Unicode internally, they seem constitutionally unable to deal with getting
those in or out. IOW, all I can really do with them is to look at their
coded values, or pass them to other APIs that expect Unicode.
If it helps, here's the code I used to get those:
Private Declare Function FindFirstFileW Lib "kernel32" (ByVal lpFileName
As Long, lpFindFileData As Any) As Long
Private Declare Function FindNextFileW Lib "kernel32" (ByVal hFindFile As
Long, lpFindFileData As Any) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As
Long) As Long
Private Const MAX_PATH = 260
Private Const INVALID_HANDLE_VALUE = -1
Private Const ERROR_NO_MORE_FILES = 18&
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA_W
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName(1 To MAX_PATH * 2) As Byte
cAlternate(1 To 14) As Byte
End Type
Public Sub DumpFilesW(ByVal Path As String)
Dim hSearch As Long
Dim wfd As WIN32_FIND_DATA_W
Dim nRet As Long
hSearch = FindFirstFileW(StrPtr(Path), wfd)
If hSearch <> INVALID_HANDLE_VALUE Then
Do
Debug.Print TrimNull(wfd.cFileName)
nRet = FindNextFileW(hSearch, wfd)
Loop While nRet
Call FindClose(hSearch)
End If
End Sub
Private Function TrimNull(ByVal Whatever As String) As String
Dim nPos As Long
nPos = InStr(Whatever, vbNullChar)
Select Case nPos
Case 0
TrimNull = Whatever
Case 1
TrimNull = ""
Case Else
TrimNull = Left$(Whatever, nPos)
End Select
End Function
Having migrated home and profile folders for ~15,000 user accounts,
I've just got 200 or so folders left with these awkward filenames,
and I really don't want to do them manually.
You'll probably find it easier to just dig in and do it manually, if that's
"all" you need to do. If you're adventurous, and want to explore the world
of Unicode, that would seem to be the ultimate answer.
Good luck... Karl