Sign in to follow this  
Followers 0
Unc3nZureD

_FileListToArray(...)

5 posts in this topic

#1 ·  Posted (edited)

A fast and straight question:

Is that possible to let it return every bmp, jpg and jpeg extension files from a folder?

The following one isn't working :S

$Pics = _FileListToArray($Path, "*.bmp;*.jpg;*.jpeg", 1)
Edited by Unc3nZureD

Share this post


Link to post
Share on other sites



Please check Melba's


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't think the standard FLTA allows multiple filters. You'd likely want to use one of the many recursive versions of FLTA that are floating around, as most of them allow multiple search filters. I'm fond of some of the team efforts that came out of thread #96952. The example below, from that thread, is at 64 lines one of the smallest and fastest around:

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

$timer = TimerInit()
$aArray = _FileListToArrayPlus(@WindowsDir, "*.dll;*.exe", 1, "", "", 1, False)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($aArray, $timer)

; #FUNCTION# =====================================================================================================================
; _FileListToArrayPlus($sPath, $sInclude = "*", $iFlag = 0, $sExcludeFolder = "", $sExclude = "", $iPathType = 0, $bRecursive = False)
; Name...........:  _FileListToArrayPlus
; Parameters ....:  $sPath: Folder to search
;     $sInclude: String to match on (wildcards allowed, multiples delimited by ;)
;     $iFlag: Returned data type. 0 = Files and folders (default), 1 = Files only, 2 = Folders only
;     $sExcludeFolder: List of folders to exclude from search (wildcards allowed, multiples delimited by ;)
;     $sExclude: List of filenames to exclude from search (wildcards allowed, multiples delimited by ;)
;     $iPathType: Returned data format. 0 = Filename only (default), 1 = Path relative to $sPath, 2 = Full path/filename
;     $bRecursive: 0 = Search $sPath folder only (default), 1 = Search $sPath and all subfolders
; Author ........:  Forum thread #96952
;===================================================================================================================================
;===================================================================================================================================
Func _FileListToArrayPlus($sPath, $sInclude = "", $iFlag = 0, $sExcludeFolder = "", $sExclude = "", $iPathType = 0, $bRecursive = False)
    Local $sRet = "", $sReturnFormat = ""
    $sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing slash
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    ; Edit include files list
    If $sInclude = "*" Then $sInclude = ""
    If $sInclude Then
        If StringRegExp($sInclude, "[/:><|]|(?s)As*z") Then Return SetError(2, 2, "") ; invalid characters test
        $sInclude = StringRegExpReplace(StringRegExpReplace($sInclude, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
        $sInclude = StringRegExpReplace($sInclude, "[][$.+^{}()]", "$0"); Ignore special characters
        $sInclude = StringReplace(StringReplace(StringReplace($sInclude, "?", "."), "*", ".*?"), ";", "$|") ; Convert ? to ., * to .*?, and ; to |
        $sInclude = "(?i)A(" & $sInclude & "$)"; case-insensitive, match from first char, terminate strings
    EndIf
    ; Edit exclude folders list
    If $sExcludeFolder Then
        $sExcludeFolder = StringRegExpReplace(StringRegExpReplace($sExcludeFolder, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
        $sExcludeFolder = StringRegExpReplace($sExcludeFolder, "[][$.+^{}()]", "$0"); Ignore special characters
        $sExcludeFolder = StringReplace(StringReplace(StringReplace($sExcludeFolder, "?", "."), "*", ".*?"), ";", "$|") ; Convert ?=.  *=.*?  ;=|
        $sExcludeFolder = "(?i)A(?!" & $sExcludeFolder & "$)"; case-insensitive, match from first char, terminate strings
    EndIf
    ; Edit exclude files list
    If $sExclude Then
        $sExclude = StringRegExpReplace(StringRegExpReplace($sExclude, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
        $sExclude = StringRegExpReplace($sExclude, "[][$.+^{}()]", "$0"); Ignore special characters
        $sExclude = StringReplace(StringReplace(StringReplace($sExclude, "?", "."), "*", ".*?"), ";", "$|") ; Convert ?=.  *=.*?  ;=|
        $sExclude = "(?i)A(?!" & $sExclude & "$)"; case-insensitive, match from first char, terminate strings
    EndIf
;   MsgBox(1,"Masks","File include: " & $sInclude & @CRLF & "File exclude: " & $sExclude & @CRLF & "Dir exclude : " & $sExcludeFolder)[/size]

    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    Local $sOrigPathLen = StringLen($sPath), $aQueue[64] = [1,$sPath], $iQMax = 63
    While $aQueue[0]
        $WorkFolder = $aQueue[$aQueue[0]]
        $aQueue[0] -= 1
        $search = FileFindFirstFile($WorkFolder & "*")
        If @error Then ContinueLoop
        Switch $iPathType
            Case 1 ; relative path
                $sReturnFormat = StringTrimLeft($WorkFolder, $sOrigPathLen)
            Case 2 ; full path
                $sReturnFormat = $WorkFolder
        EndSwitch
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If @extended Then ; Folder
                If $sExcludeFolder And Not StringRegExp($file, $sExcludeFolder) Then ContinueLoop
                If $bRecursive Then
                    If $aQueue[0] = $iQMax Then
                        $iQMax += 128
                        ReDim $aQueue[$iQMax + 1]
                    EndIf
                    $aQueue[0] += 1
                    $aQueue[$aQueue[0]] = $WorkFolder & $file & ""
                EndIf
                If $iFlag = 1 Then ContinueLoop
             $sRet &= $sReturnFormat & $file & "|"
            Else ; File
                If $iFlag = 2 Then ContinueLoop
    If $sInclude And Not StringRegExp($file, $sInclude) Then ContinueLoop
    If $sExclude And Not StringRegExp($file, $sExclude) Then ContinueLoop
    $sRet &= $sReturnFormat & $file & "|"
            EndIf
        WEnd
        FileClose($search)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc

edit: fixed screwed up code tags (repeatedly)

Edited by Spiff59

Share this post


Link to post
Share on other sites

Look here too

Ciao.


apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
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
Sign in to follow this  
Followers 0