Jump to content
Sign in to follow this  
motionman95

Wildcards and _FileListToArray

Recommended Posts

motionman95

I'm trying to put multiple wildcards into the _FileListToArray function, but the way I'm doing it isn't working:

_FileListToArray($FontDir, "*.ttf *.otf", 1)

Basically, I'm just trying to make it look for files with .ttf or .otf extensions.


Share this post


Link to post
Share on other sites
martin

I'm trying to put multiple wildcards into the _FileListToArray function, but the way I'm doing it isn't working:

_FileListToArray($FontDir, "*.ttf *.otf", 1)

Basically, I'm just trying to make it look for files with .ttf or .otf extensions.

If you look in File.au3 you will see that only one file type is allowed for, so you will have to use _FileListToArray twice and then combine the arrays returned.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Malkey

If there are not any other files that fit the extension ".?tf" other than ".ttf" or ".otf", I would use Danny35d method.

Here is an example of martin's method. That is, use _FileListToArray twice and combine the arrays returned.

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

$aArray = _FileListToArrayMultiSelect(@DesktopDir, "*.exe", "*.htm?", 1)

;$FontDir = "Directory Path"
;$aArray = _FileListToArrayMultiSelect($FontDir, "*.ttf",  "*.otf", 1)

_ArrayDisplay($aArray, "Files Selected")

Func _FileListToArrayMultiSelect($dir, $search1, $search2, $iFlag = 0)
    Local $FileList, $FileList1, $Num, $Err = 0, $Err2 = 0
    $FileList = _FileListToArray($dir, $search1, $iFlag)
    If @error > 0 Then  $Err = 1    
    $FileList1 = _FileListToArray($dir, $search2, $iFlag)
    If @error > 0 Then $Err2 = 1
    
    If ($Err2 = 1) And ($Err = 0) Then Return $FileList
    If ($Err2 = 0) And ($Err = 1) Then Return $FileList1
    If ($Err2 = 0) And ($Err = 0) Then
        $Num = UBound($FileList)
        _ArrayConcatenate($FileList, $FileList1)
        $FileList[0] = $FileList[0] + $FileList[$Num]
        _ArrayDelete($FileList, $Num)
        Return $FileList
    EndIf
    MsgBox(0, "", "No Files\Folders Found.")
EndFunc  ;==>_FileListToArrayMultiSelect

Share this post


Link to post
Share on other sites
motionman95

@Malkey and Martin: Thanks for the suggestion and the code! It works perfectly! :P *Does the happy dance*


Share this post


Link to post
Share on other sites
martin

@motionman95 - NP, but I'm glad Makley volunteered to do the hard work :P

@Makey. That's a nice little function. If you had the $search parameter as a concatenated string and had the next parameter as the separator used then it could be used for any number of different file types.

#include <File.au3>
 #include <Array.au3>
 
 $aArray = _FileListToArrayMultiSelect(@ScriptDir, "*.bmp;*.jpg;*.tff", ";", 1)
 
 
 Func _FileListToArrayMultiSelect($dir, $searchlist, $Separator, $iFlag = 0)
     Local $FileList[1] = [0], $Filelist1, $iN, $Num, $search
 
     $search = StringSplit($searchlist, $Separator)
     If $search[0] > 0 Then
         For $iN = 1 To $search[0]
             $Filelist1 = _FileListToArray($dir, $search[$iN], $iFlag)
             If Not @error Then
                 $Num = UBound($FileList)
                 _ArrayConcatenate($FileList, $Filelist1)
                 $FileList[0] = $FileList[0] + $FileList[$Num]
                 _ArrayDelete($FileList, $Num)
             EndIf
         Next
     EndIf
     Return $FileList;could be [0]
 
 EndFunc ;==>_FileListToArrayMultiSelect
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Malkey

#include <File.au3>
 #include <Array.au3>
 
 $aArray = _FileListToArrayMultiSelect(@ScriptDir, "*.bmp;*.jpg;*.tff", ";", 1)
 
 
 Func _FileListToArrayMultiSelect($dir, $searchlist, $Separator, $iFlag = 0)
     Local $FileList[1] = [0], $Filelist1, $iN, $Num, $search
 
     $search = StringSplit($searchlist, $Separator)
     If $search[0] > 0 Then
         For $iN = 1 To $search[0]
             $Filelist1 = _FileListToArray($dir, $search[$iN], $iFlag)
             If Not @error Then
                 $Num = UBound($FileList)
                 _ArrayConcatenate($FileList, $Filelist1)
                 $FileList[0] = $FileList[0] + $FileList[$Num]
                 _ArrayDelete($FileList, $Num)
             EndIf
         Next
     EndIf
     Return $FileList;could be [0]
 
 EndFunc;==>_FileListToArrayMultiSelect
martin

A much better function, more versatile, nicely done.

Malkey

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.