Jump to content

Another _FileListToArray()


SmOke_N
 Share

Recommended Posts

  • Moderators

;===============================================================================
;
; Description:    lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax:          _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '')
; Parameter(s):     $sPath = Path to generate filelist for
;                   $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches 
;                           Example *.exe; *.txt will find all .exe and .txt files
;                  $iFlag = determines weather to return file or folders or both.
;                   $sExclude = exclude a file from the list by all or part of its name 
;                           Example: Unins* will remove all files/folders that start with Unins
;                       $iFlag=0(Default) Return both files and folders
;                      $iFlag=1 Return files Only
;                       $iFlag=2 Return Folders Only
;
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of files and folders in the specified path
;                       On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
;                       @Error or @extended = 1 Path not found or invalid
;                       @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude
;                      @Error or @extended = 3 Invalid $iFlag
;                       @Error or @extended = 4 No File(s) Found
;
; Author(s):        SmOke_N
; Note(s):          The array returned is one-dimensional and is made up as follows:
;                   $array[0] = Number of Files\Folders returned
;                   $array[1] = 1st File\Folder
;                   $array[2] = 2nd File\Folder
;                   $array[3] = 3rd File\Folder
;                   $array[n] = nth File\Folder
;
;                   All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example
;                   The Reserved file is then read into an array, then deleted
;===============================================================================

Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $f_recurse = True, $f_full_path = True)

    If FileExists($s_path) = 0 Then Return SetError(1, 1, 0)

    ; Strip trailing backslash, and add one after to make sure there's only one
    $s_path = StringRegExpReplace($s_path, "[\\/]+\z", "") & "\"

    ; Set all defaults
    If $s_mask = -1 Or $s_mask = Default Then $s_mask = "*.*"
    If $i_flag = -1 Or $i_flag = Default Then $i_flag = 0
    If $s_exclude = -1 Or $s_exclude = Default Then $s_exclude = ""

    ; Look for bad chars
    If StringRegExp($s_mask, "[/:><\|]") Or StringRegExp($s_exclude, "[/:><\|]") Then
        Return SetError(2, 2, 0)
    EndIf

    ; Strip leading spaces between semi colon delimiter
    $s_mask = StringRegExpReplace($s_mask, "\s*;\s*", ";")
    If $s_exclude Then $s_exclude = StringRegExpReplace($s_exclude, "\s*;\s*", ";")

    ; Confirm mask has something in it
    If StringStripWS($s_mask, 8) = "" Then Return SetError(2, 2, 0)
    If $i_flag < 0 Or $i_flag > 2 Then Return SetError(3, 3, 0)

    ; Validate and create path + mask params
    Local $a_split = StringSplit($s_mask, ";"), $s_hold_split = ""
    For $i = 1 To $a_split[0]
        If StringStripWS($a_split[$i], 8) = "" Then ContinueLoop
        If StringRegExp($a_split[$i], "^\..*?\..*?\z") Then
            $a_split[$i] &= "*" & $a_split[$i]
        EndIf
        $s_hold_split &= '"' & $s_path & $a_split[$i] & '" '
    Next
    $s_hold_split = StringTrimRight($s_hold_split, 1)
    If $s_hold_split = "" Then $s_hold_split = '"' & $s_path & '*.*"'

    Local $i_pid, $s_stdout, $s_hold_out, $s_dir_file_only = "", $s_recurse = "/s "
    If $i_flag = 1 Then $s_dir_file_only = ":-d"
    If $i_flag = 2 Then $s_dir_file_only = ":D"
    If Not $f_recurse Then $s_recurse = ""

    $i_pid = Run(@ComSpec & " /c dir /b " & $s_recurse & "/a" & $s_dir_file_only & " " & $s_hold_split, "", @SW_HIDE, 4 + 2)

    While 1
        $s_stdout = StdoutRead($i_pid)
        If @error Then ExitLoop
        $s_hold_out &= $s_stdout
    WEnd

    $s_hold_out = StringRegExpReplace($s_hold_out, "\v+\z", "")
    If Not $s_hold_out Then Return SetError(4, 4, 0)

    ; Parse data and find matches based on flags
    Local $a_fsplit = StringSplit(StringStripCR($s_hold_out), @LF), $s_hold_ret
    $s_hold_out = ""

    If $s_exclude Then $s_exclude = StringReplace(StringReplace($s_exclude, "*", ".*?"), ";", "|")

    For $i = 1 To $a_fsplit[0]
        If $s_exclude And StringRegExp(StringRegExpReplace( _
            $a_fsplit[$i], "(.*?[\\/]+)*(.*?\z)", "\2"), "(?i)\Q" & $s_exclude & "\E") Then ContinueLoop
        If StringRegExp($a_fsplit[$i], "^\w:[\\/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i]
        If $f_full_path Then
            $s_hold_ret &= $a_fsplit[$i] & Chr(1)
        Else
            $s_hold_ret &= StringRegExpReplace($a_fsplit[$i], "((?:.*?[\\/]+)*)(.*?\z)", "$2") & Chr(1)
        EndIf
    Next

    $s_hold_ret = StringTrimRight($s_hold_ret, 1)
    If $s_hold_ret = "" Then Return SetError(5, 5, 0)

    Return StringSplit($s_hold_ret, Chr(1))
EndFunc

Examples:

#include <array.au3>; Only used for _ArrayDisplay
;Return all files/folders
$hFilesFolders = _FileListToArrayEx(@HomeDrive)
_ArrayDisplay($hFilesFolders, 'Files and Folders')

;Return all .exe and .txt files
$hFilesFolders = _FileListToArrayEx(@HomeDrive, '*.exe; *.txt')
_ArrayDisplay($hFilesFolders, 'Exe and Txt')

;Return all files/folders that start with P
$hFilesFolders = _FileListToArrayEx(@HomeDrive, 'P*.*')
_ArrayDisplay($hFilesFolders, 'Files and Folders')

;Return all files that start with M
$hFilesFolders = _FileListToArrayEx(@HomeDrive, 'M*.*', 1);May have none for this example
_ArrayDisplay($hFilesFolders, 'Files')

;Return all folders that start with M
$hFilesFolders = _FileListToArrayEx(@HomeDrive, 'M*.*', 2)
_ArrayDisplay($hFilesFolders, 'Folders')

;Return all files and folders unless they start with M
$hFilesFolders = _FileListToArrayEx(@HomeDrive, Default, Default, 'M*')
_ArrayDisplay($hFilesFolders, 'Files and Folders')

;Return all files unless they start with M
$hFilesFolders = _FileListToArrayEx(@HomeDrive, -1, 1, 'M*');May have none for this example
_ArrayDisplay($hFilesFolders, 'Files')

;Return all folders unless they start with M
$hFilesFolders = _FileListToArrayEx(@HomeDrive, -1, 2, 'M*')
_ArrayDisplay($hFilesFolders, 'Folders')

Edit:

Made an exception for -1 or Default, I changed the examples to use both -1 and Default so you could see.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

pretty sharp... Ron!

8)

Thanks :lmao:

For those that don't want to write to a temp folder with the info:

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '')
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        Local $iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC]  _
                & '" /b /o-e /od', '', @SW_HIDE, 6)
        While 1
            $sRead &= StdoutRead($iPid)
            If @error Then ExitLoop
        WEnd
    Next
    If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft($aFSplit[$iCC], _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 2
                If Not StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi,

thanks - could be helpful. Although, it seems to be a long code for the func. :lmao:

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Hi,

thanks - could be helpful. Although, it seems to be a long code for the func. :)

So long,

Mega

44 lines is long? :lmao: .... Hmm, I have some that are 100+ lol. This one just does so many things that if you cut out the option to do multiple extension searches and or the exception mode, it would be much shorter :geek: . But then that kind of defeats the purpose :ph34r:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thank you very much.

It's a very fine implementation of the previous _FileListToArray UDF.

I hope it will substitute the _FileListToArray UDF in the AutoIt package.

Just a little note about the temporary file: why do not use another optional parameter for choosing if using it or not (default = no temporary file)?

IMHO, if you know that you have to search a lot of files (i. e. c:\*.exe), it's better writing the list on a temporary file, while on the contrary for minor searches (i. e. c:\temp\*.tmp) no temp. files are needed.

Regards

Peppe

Edited by gcriaco
Link to comment
Share on other sites

  • Moderators

Thank you very much.

It's a very fine implementation of the previous _FileListToArray UDF.

I hope it will substitute the _FileListToArray UDF in the AutoIt package.

Just a little note about the temporary file: why do not use another optional parameter for choosing if using it or not (default = no temporary file)?

I think that, if you know that you have to search a lot of files (i. e. c:\*.exe), it's better writing the list on a temporary file, while on the contrary for minor searches (i. e. c:\temp\*.tmp) no temp. files are needed.

Regards

Peppe

That's why I wrote the 2nd part, If someone wants to use either or. I often submit re-writes, but Jdeb finds good reasons on not to use them, either I should just add to something, or I've not thought through enough error handling, as most of the UDF's I write are usually case specific.

If people think it should at least be submited, then I'll add the 5 or 6 line "option". (ha, th.meger... that means yes it would be larger :lmao: )

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

@Smoke_N

What about this merging of your 2 UDF versions?

;===============================================================================
; Description:      lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax:           _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $bTmpFile = False)
; Parameter(s):     $sPath = Path to generate filelist for
;                   $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches
;                       Example *.exe; *.txt will find all .exe and .txt files
;                   $iFlag = determines weather to return file or folders or both.
;                   $sExclude = exclude a file from the list by all or part of its name
;                       Example: Unins* will remove all files/folders that start with Unins
;                   $iFlag=0(Default) Return both files and folders
;                       $iFlag=1 Return files Only
;                       $iFlag=2 Return Folders Only
;                   $bTmpFile = Boolean value for specifying if using a temp. file
;                       $bTmpFile = True All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example
;                                   The Reserved file is then read into an array, then deleted
;                       $bTmpFile = False No .tmp file is used
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of files and folders in the specified path
;                   On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
;                       @Error or @extended = 1 Path not found or invalid
;                       @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude
;                       @Error or @extended = 3 Invalid $iFlag
;                       @Error or @extended = 4 No File(s) Found
; Author(s):        SmOke_N
; Note(s):      The array returned is one-dimensional and is made up as follows:
;               $array[0] = Number of Files\Folders returned
;               $array[1] = 1st File\Folder
;               $array[2] = 2nd File\Folder
;               $array[3] = 3rd File\Folder
;               $array[n] = nth File\Folder
;===============================================================================

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $bTmpFile = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    If $bTmpFile Then
        Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
        $sTFolder = $oFSO.GetSpecialFolder(2)
        Local $hOutFile = @TempDir & $oFSO.GetTempName
    EndIf
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        If $bTmpFile Then
            RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC]  _
                    & '" /b /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
            $sRead &= FileRead($hOutFile)
            If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
            FileDelete($hOutFile)
        Else
            Local $iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC]  _
                    & '" /b /o-e /od', '', @SW_HIDE, 6)
            While 1
                $sRead &= StdoutRead($iPid)
                If @error Then ExitLoop
            WEnd
        EndIf
    Next
    If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft($aFSplit[$iCC], _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 2
                If Not StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc

Issue:

Return SetError(2,2,"") => doesn't return error

SetError(2)

return @error => it's OK

Testing the UDF output could be:

If IsArray($hFilesFolders) then

_ArrayDisplay($hFilesFolders, 'Folders')

Else

msgbox(0,"_FileListToArrayEx Error" , $hFilesFolders)

EndIf

Link to comment
Share on other sites

  • Moderators

Those were the 6 lines I was talking about adding to merge them.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

what about the error codes trapping?

I am wrong or we have to change the code as follows:

Return SetError(2,2,"") => SetError(2)

return @error

Edit: Sorry for the mistake. Anything is OK.

Edited by gcriaco
Link to comment
Share on other sites

  • Moderators

what about the error codes trapping?

I am wrong or we have to change the code as follows:

Return SetError(2,2,"") => SetError(2)

return @error

I have to check that gcriaco, to be honest, it should return 2 as the error and 2 as extended and nothing as the return value... If it doesn't then Valik will need to see an example of what we've come up with.

Edit:

I ran this code

_FileListToArrayEx(@DesktopDir, '')
MsgBox(0, 'Error', @error)
And the error returned was 2 as it should be. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I have to check that gcriaco, to be honest, it should return 2 as the error and 2 as extended and nothing as the return value... If it doesn't then Valik will need to see an example of what we've come up with.

Edit:

I ran this code

_FileListToArrayEx(@DesktopDir, '')
MsgBox(0, 'Error', @error)
And the error returned was 2 as it should be.
I'm wrong. Sorry for the mistake. Anything is OK.

As I already asked for, devs please consider to substitute the actual _FileListToArray UDF with the Smoke_on function.

Edited by gcriaco
Link to comment
Share on other sites

  • 3 months later...

I'm wrong. Sorry for the mistake. Anything is OK.

As I already asked for, devs please consider to substitute the actual _FileListToArray UDF with the Smoke_on function.

For anyone that may need it, here's a faster version of SmOke_N's UDF. It's pretty fast now, It returns recursive results of c:\ in 3-5 seconds on my laptop, slightly slower if using exclusions. It also handles multiple exclusions with wildcards. Hope you don't mind, SmOke_N!

;===============================================================================
;
; Description:      lists all or preferred files and or folders in a specified path RECURSIVELY (Similar to using Dir with the /B Switch)
; Syntax:           _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
; Parameter(s):     $sPath = Path to generate filelist for
;               $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches
;                     Example *.exe; *.txt will find all .exe and .txt files
;                   $iFlag = determines weather to return file or folders or both.
;               $sExclude = exclude a file from the list by all or part of its name.  Now you can use multiple excludes with with or w/o wildcards.
;                     Example: Unins* will remove all files/folders that start with Unins
;                  $iFlag=0(Default) Return both files and folders
;                       $iFlag=1 Return files Only
;                  $iFlag=2 Return Folders Only
;               $iRecurse = True = Recursive, False = Standard
;
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of files and folders in the specified path
;                        On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
;                  @Error or @extended = 1 Path not found or invalid
;                  @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude
;                       @Error or @extended = 3 Invalid $iFlag
;                     @Error or @extended = 4 No File(s) Found
;
; Author(s):        SmOke_N
; Note(s):      The array returned is one-dimensional and is made up as follows:
;               $array[0] = Number of Files\Folders returned
;               $array[1] = 1st File\Folder
;               $array[2] = 2nd File\Folder
;               $array[3] = 3rd File\Folder
;               $array[n] = nth File\Folder
;
;               All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example
;               The Reserved file is then read into an array, then deleted
;===============================================================================

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['', '/', ':', '>', '<', '|']
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
    $sPath = StringReplace($sPath, "\\", "\")
    Local $aFSplit, $hTempFile
    Local $sTempFile = @TempDir & "\FLTAR.txt"
    If FileExists($sTempFile) Then FileDelete($sTempFile)
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        Local $iPid
        If Not $iRecurse Then
            Switch $iFlag
                Case 0
                    $iPid = RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & '' & $aSplit[$iCC] & '" /b /o-e /od >> "' & $sTempFile & '"', '', @SW_HIDE)
                Case 1
                    $iPid = RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & '' & $aSplit[$iCC] & '" /b /o-e /od /a-d >> "' & $sTempFile & '"', '', @SW_HIDE)
                Case 2
                    $iPid = RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & '' & $aSplit[$iCC] & '" /b /o-e /od /ad >> "' & $sTempFile & '"', '', @SW_HIDE)
            EndSwitch
        Else
            Switch $iFlag
                Case 0
                    $iPid = RunWait(@Comspec & ' /c dir "' & $sPath & '' & $aSplit[$iCC] & '" /b /o-e /od /s /a >> "' & $sTempFile & '"', '', @SW_HIDE)
                Case 1
                    $iPid = RunWait(@Comspec & ' /c dir "' & $sPath & '' & $aSplit[$iCC] & '" /b /o-e /od /s /a-d >> "' & $sTempFile & '"', '', @SW_HIDE)
                Case 2
                    $iPid = RunWait(@Comspec & ' /c dir "' & $sPath & '' & $aSplit[$iCC] & '" /b /o-e /od /s /ad >> "' & $sTempFile & '"', '', @SW_HIDE)
            EndSwitch
        EndIf
    Next
    $hTempFile = FileOpen($sTempFile, 0)
    $aFSplit = StringSplit( StringStripCR( FileRead($hTempFile, FileGetSize($sTempFile))), @LF)
    FileClose($hTempFile)
    
    If $sExclude Then
        Local $sHold
        Local $sCutString, $iGo, $aStrTest
        Local $aExclude = StringSplit($sExclude, ";")
        
        For $h=1 to $aExclude[0]
            $aExclude[$h] = StringReplace($aExclude[$h], '.', '\.')
            $aExclude[$h] = StringReplace($aExclude[$h], '*', '.*')
            $aExclude[$h] = "(?i)(" & $aExclude[$h] & ")"   
        Next
        
        For $i=1 to $aFSplit[0]
            $sCutString = StringTrimLeft($aFSplit[$i], StringInStr($aFSplit[$i], "\", 0, -1))
            $iGo = 1
            For $j=1 to $aExclude[0]
                $aStrTest = StringRegExp($sCutString, $aExclude[$j], 1)
                If IsArray($aStrTest) Then
                    If $aStrTest[0] = $sCutString Then $iGo = 0
                EndIf
            Next
            If $iGo Then $sHold &= $aFSplit[$i] & Chr(1)
        Next
        If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
        Return SetError(4, 4, '')
    Else
        Return $aFSplit
    EndIf
EndFunc
Link to comment
Share on other sites

  • 3 weeks later...
  • Moderators

but,why i can not use the EnCodeIt 2.0!

Did you pay yet?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

So many people have been making these "FileSearch" type functions lately, but I'm just fine with Larry's _FileSearch :)

Kurt

Is this post really necessary? And as I've asked before, do you even know what this one does?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

"lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)"

And the I posted since there have been 2-3 different posts about similar UDF's this past week, that's all. Wasn't saying that this was of bad quality or anything. But you're right, that post was unnecessary, not that everyone posts necessary stuff in this forum.

Kurt

EDIT: Spelling Correction

Edited by _Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

  • 1 month later...

HI,

Script is very nice. But in case we want to serach more file types & number is 6-7. then time to show result is 6 times than normal if we add /s switch. Because its going through loop for each file type.

RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC] _

& '" /b /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)

but if we use command form like dir /s /b c:\*.dat; c:\*.txt; c:\*.mp3 then its showing results for all files types in one go..

Is it possible to modify above script in this way to save time..

Please help.

Thx Rahul

Edited by Rahul Rohela
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...