Jump to content

Looking to improve on FileListToArray to include directory recursion


Recommended Posts

I've seen a number of attempts to improve on this function and they typically use the DOS DIR command to achieve that goal. The problem with that is that DOS still does not deal with filenames with accented characters properly.

While I too have created my own FileSearch function, it too uses DIR and has this same shortcoming.

However, FileFindNextFile DOES properly return back accented chars.

Does anyone have a snippet that shows how to do directory recursion using only FileFinds?

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=58558

- weaponx's regexp version for that, quite fast and versatile.

Here is another attempt for that, not as fast or versatile as weaponx's. Add a flag or check to preform a recursive search or not:

#include <Array.au3>

Dim $aRet = _HelperFunc('C:\', '*.txt')
If IsArray($aRet) Then _ArrayDisplay($aRet)

Func _HelperFunc($sDirectory, $sFind = '*.*')
    If StringRight($sDirectory, 1) <> '\' Then $sDirectory &= '\'
    Local $aReturn[2]
    $aReturn[0] = 1
    _RecursiveSearch($aReturn, $sDirectory, $sFind)
    $aReturn[0] -= 1
    Return $aReturn
EndFunc


Func _RecursiveSearch(ByRef $aReturn, $sWorkingDirectory, $sFindFile)
    Local $hFile, $hFolder
    Local $FileName, $FolderName
    
    $hFile = FileFindFirstFile($sWorkingDirectory & $sFindFile)
   
    If $hFile <> -1 Then
        While 1
            $FileName = FileFindNextFile($hFile)
            If @error Then ExitLoop
            ReDim $aReturn[$aReturn[0]+1]
            $aReturn[$aReturn[0]] = $sWorkingDirectory & $FileName
            $aReturn[0]+=1
        WEnd
        FileClose($hFile)
    EndIf

    $hFolder = FileFindFirstFile($sWorkingDirectory & '\*')
    If $hFolder = -1 Then Return
    
    While 1
        $FolderName = $sWorkingDirectory & FileFindNextFile($hFolder)
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($FolderName), 'D') Then _RecursiveSearch($aReturn, $FolderName & '\', $sFindFile)
    WEnd
    FileClose($hFolder)
EndFunc

I didn't see any function that doesn't use DIR command that is able to list files within compress files like .ZIP etc, yet.

Link to comment
Share on other sites

Thanks for the info...

From those posts I was able to find that Randal is updating the FileListToArray():

http://www.autoitscript.com/forum/index.ph...mp;#entry372209

I'm going to use WeaponX's RecusiveFileSearch() for now as that is self contained and seems to do what I was wanting in a fast amount of time (i'm looking in over 1,000 folders for 40,000+ files.

Thanks again.

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...