Jump to content

[SOLVED] Help With _FileListToArrayRec()


Go to solution Solved by ioa747,

Recommended Posts

Posted (edited)

Hello,

I am searching files (e.g.) *.jpg inside (e.g.) 'cramy' folders like

C:\AutoIt\[some folders]\cramy\*.jpg

AND as well .jpg inside folders ending with 25: 

C:\AutoIt\[some folders]\[some folders]\[some folders]\*25\*.jpg

I have some code: 

Local $aJPG[1]=[0], $aOtherJPG[1]=[0]
For $i = 1 To $aDrive[0]
    $aJPG = _FileListToArrayRec($aDrive[$i] & "\", "cramy", $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    For $j = 1 To aJPG[0]
        $aFic1 = _FileListToArray($aJPG[$j], "*.jpg", $FLTA_FILES, True)
        $num = _ArrayConcatenate(aJPG, aJPG1, 1)
        $aJPG[0] = $num - 1
    Next

    $aOtherJPG = _FileListToArrayRec($aDrive[$i] & "\", "*25", $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    For $j = 1 To $aOtherJPG[0]
        $aOtherJPG1 = _FileListToArray($aOtherJPG[$j], "*.jpg", $FLTA_FILES, True)
        $num = _ArrayConcatenate($aOtherJPG, $aOtherJPG1, 1)
        aOtherJPG[0] = $num - 1
    Next
Next

Is it possible to shorten the code ?
I tried:
 

$aJPG = _FileListToArrayRec($aDrive[$i] & '\', 'cramy||;*25||', $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)

But it doesn't work !


Thanks for your help!

C.

Edited by cramaboule
  • Solution
Posted


I did it like this.

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

Local $aDrive[] = [2, "C:\", "D:\"]
Local $aDir, $aJpg
Local $aResult = 0
Local $bFirstArray = True

For $i = 1 To $aDrive[0]
    $aDir = _FileListToArrayRec($aDrive[$i], "cramy;*25", $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    If @error Then
        ConsoleWrite("No folders found matching the criteria." & @CRLF)
    Else
        For $j = 1 To $aDir[0]
            $aJpg = _FileListToArray($aDir[$j], "*.jpg", $FLTA_FILES, True)
            If @error Then
                ConsoleWrite("No files found matching the criteria, in folder: " & $aDir[$j] & @CRLF)
            Else
                If $bFirstArray Then
                    $aResult = $aJpg
                    $bFirstArray = False
                Else
                    _ArrayConcatenate($aResult, $aJpg, 1)
                    $aResult[0] = UBound($aResult) - 1
                EndIf
            EndIf
        Next
    EndIf
Next

; If $aResult is an array, display it.
If IsArray($aResult) Then 
    _ArrayDisplay($aResult, "All .jpg Files Found (" & $aResult[0] & " Total)")
Else 
    ConsoleWrite("SUMMARY: No .jpg files were successfully collected." & @CRLF)
EndIf

 

I know that I know nothing

Posted
18 minutes ago, ioa747 said:


I did it like this.

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

Local $aDrive[] = [2, "C:\", "D:\"]
Local $aDir, $aJpg
Local $aResult = 0
Local $bFirstArray = True

For $i = 1 To $aDrive[0]
    $aDir = _FileListToArrayRec($aDrive[$i], "cramy;*25", $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    If @error Then
        ConsoleWrite("No folders found matching the criteria." & @CRLF)
    Else
        For $j = 1 To $aDir[0]
            $aJpg = _FileListToArray($aDir[$j], "*.jpg", $FLTA_FILES, True)
            If @error Then
                ConsoleWrite("No files found matching the criteria, in folder: " & $aDir[$j] & @CRLF)
            Else
                If $bFirstArray Then
                    $aResult = $aJpg
                    $bFirstArray = False
                Else
                    _ArrayConcatenate($aResult, $aJpg, 1)
                    $aResult[0] = UBound($aResult) - 1
                EndIf
            EndIf
        Next
    EndIf
Next

; If $aResult is an array, display it.
If IsArray($aResult) Then 
    _ArrayDisplay($aResult, "All .jpg Files Found (" & $aResult[0] & " Total)")
Else 
    ConsoleWrite("SUMMARY: No .jpg files were successfully collected." & @CRLF)
EndIf

 

$aDir = _FileListToArrayRec($aDrive[$i], "cramy;*25", $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)

Arrr,.... that's the syntax I was looking for !

Thanks

 

 

  • cramaboule changed the title to [SOLVED] Help With _FileListToArrayRec()

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
×
×
  • Create New...