Modify

Opened 6 years ago

Closed 6 years ago

#2453 closed Bug (Fixed)

FileFindNextFile can find not-matching mask files if non-English letters presented in the file name

Reported by: anonymous Owned by: Jon
Milestone: 3.3.11.0 Component: AutoIt
Version: 3.3.8.1 Severity: None
Keywords: Cc:

Description

It seems windows bug/feature, but still...
it affect results of FileListToArray
To reproduce - run in Unicode:

#include <Array.au3>
#include "File.au3"

$path = 'd:\12345' ;folder with is used to create files

$files = StringSplit("file.txt|file1.txt|file2.txt|prefix_file.txt|йfile.txt|начало file.txt|начало_file.txt|йfilйe.tйxt", "|")
FileChangeDir($path)
For $i = 1 To UBound($files) - 1
    _FileCreate($files[$i])
Next

$FileList1 = _FileListToArray($path, 'file*.txt')
_ArrayDisplay($FileList1, 'Find Files')

For $i = 1 To UBound($files) - 1
    FileDelete($files[$i])
Next

Alternative:

Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $aResult, $sFile, $sFileList, $sDelim = "|"
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "\"
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    $hSearch = FileFindFirstFile($sPath & '*')
    If @error Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If ($iFlag + @extended = 2) Then ContinueLoop
        $aResult = DllCall('shlwapi.dll', 'int', 'PathMatchSpecW', 'wstr', $sFile, 'wstr', $sFilter)
        If (Not @error) And ($aResult[0]) Then $sFileList &= $sDelim & $sFile
    WEnd
    FileClose($hSearch)
    If Not $sFileList Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc   ;==>_FileListToArrayEx

Link : http://autoit-script.ru/index.php/topic,4285.0.html

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by Jon

Interesting one. I read around and found that the WinAPI FindFirstFile functions actually search both the long and short versions of a filename. If you look at those test files you can see that the short file name versions do indeed match the filter.

0/12/2013 20:01 0 file.txt
0/12/2013 20:01 0 file1.txt
0/12/2013 20:01 0 file2.txt
0/12/2013 20:01 0 PREFIX~1.TXT prefix_file.txt
0/12/2013 20:01 0 FILE~1.TXT йfile.txt
0/12/2013 20:01 0 FILE~3.TXT йfilйe.tйxt
0/12/2013 20:01 0 FILE~2.TXT начало file.txt
0/12/2013 20:01 0 _FILE~1.TXT начало_file.txt

That's not really what I would have expected...

comment:2 Changed 6 years ago by Jon

Updated the documentation.

comment:3 Changed 6 years ago by Jon

  • Milestone set to 3.3.11.0
  • Owner set to Jon
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [9455] in version: 3.3.11.0

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.