kellyethridge / VBCorLib

The VBCorLib framework brings many of the powerful .NET classes to VB6.
http://www.kellyethridge.com/vbcorlib/
MIT License
112 stars 28 forks source link

file name contains: ChrW(-29731) HasIllegalCharacters Error #68

Closed wq1282 closed 3 years ago

wq1282 commented 3 years ago
Dim file
For Each file In corlib.Directory.GetFiles(corlib.Environment.GetFolderPath(Desktop) & "\")
    Debug.Print Now, file
Next

`--------------------------- Project1 Run-time error '5':

Invalid characters in path. OK

Hello, I tested the cause of the phenomenon Because the file name contains: ChrW(-29731) In Chinese characters, it is:话 For example, the file name I tested was 神话.txt

The reason for the mistake seems to have come from: Path.cls Path.HasIllegalCharacters Select Case PathChars(i) Case vbQuoteChar, vbLessThanChar, vbGreaterThanChar, vbPipeChar, Is < vbSpaceChar ...

case Is < vbSpaceChar < 32 ?
-29731 < 32 Error but -29731 < 0 Not 0<xxx<32

Hope to be more compatible with Unicode characters, looking forward to your solution

Private Function HasIllegalCharacters(ByRef Path As String) As Boolean Dim PathChars() As Integer Dim i As Long
PathChars = AllocChars(Path)
For i = 0 To Len(Path) - 1 Select Case PathChars(i) Case vbQuoteChar, vbLessThanChar, vbGreaterThanChar, vbPipeChar, Is < vbSpaceChar MsgBox "HasIllegalCharacters:Error:" & i & "|" & PathChars(i) HasIllegalCharacters = True Exit For End Select Next
FreeChars PathChars End Function

Originally posted by @wq1282 in https://github.com/kellyethridge/VBCorLib/issues/52#issuecomment-692592502

kellyethridge commented 3 years ago

OK, thank you for looking into this. This will be fixed for the upcoming release.