Jump to content
Sign in to follow this  
SmOke_N

Another _FileListToArray()

Recommended Posts

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

As soon as I can wrap my head around what you just said... sure :whistle: 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.

Share this post


Link to post
Share on other sites

Maybe this is what you are talking about? (Remembering to use regular Code tags and not AutoIt Code tags this time :whistle: )

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] = ['\', '/', ':', '>', '<', '|']
    $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';')
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    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, '')
    Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
    $sTFolder = $oFSO.GetSpecialFolder(2)
    Local $hOutFile = @TempDir & $oFSO.GetTempName
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit
    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]
        $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" '
    Next
    $sHoldSplit = StringTrimRight($sHoldSplit, 1)
    If $iRecurse Then
        RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
    EndIf
    $sRead &= FileRead($hOutFile)
    If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
    FileDelete($hOutFile)
    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
                If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then 
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
                If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then 
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
            Case 2
                If Not StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop
                If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then 
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc

Edit:

Had to fix recursive search... default is no recurse.

Edit2:

Had to fix recursive search output blah!

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.

Share this post


Link to post
Share on other sites

Great job, but doesn't work for file and directory with spécial caracters like : C:\Répertoire N°1

Cause the redirector '>' don't like other language than English :shocked:

So if we plan to use it for rename files/directory, it doesn't work.

Thanks

Thierry

Share this post


Link to post
Share on other sites

Maybe I'm missing something... Can this be used to search sub folders?

:) ::Said reluctantly, knowing there's something obvious::

The last parameter, just put True ($iRecurse)

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.

Share this post


Link to post
Share on other sites

a small thing: is there a possibility to exclude certain subfolders?

for example: i dont want results from the recycle bin to popup between my results (and i dont like the idea of running cmd, but i'll live with that for now)

Share this post


Link to post
Share on other sites

a small thing: is there a possibility to exclude certain subfolders?

for example: i dont want results from the recycle bin to popup between my results (and i dont like the idea of running cmd, but i'll live with that for now)

Hi,

If you use new _FileListToArray udf in my signature, no DOS; and exclude on folders;

#include<array.au3>
#include<_FileListToArrayNew2g.au3>
Local $Message = "all              files    ?",$Exclude, $filter ="*",$s_cumulate,$timerstamp1 = TimerInit()
Local $sPath = @ScriptDir, $Flag=2, $Recurse=1, $BasDir=1, $filter = "*",$Exclude="miner"
$ar_Array = _FileListToArray3 ($sPath, $filter, $Flag, $Recurse, $BasDir, $Exclude) 
ConsoleWrite($Message & "=" & UBound($ar_Array) - 1 & @TAB & " _FileListToArrayRecurse3 " & @TAB & _
        ":" & @TAB & Round(TimerDiff($timerstamp1)) & "" & @TAB & " msec" & @LF)
;~ _ArrayDisplay($ar_Array)

for $a= 1 to UBound($ar_Array)-1
    $ar_Array2 = _FileListToArray3 ($ar_Array[$a], "*", 1, 0, 0) ;($sPath, $filter, $Flag, $Recurse, $BasDir, $Exclude) 
    $s_cumulate&=_ArrayToString($ar_Array2,"|",1)
Next
$ar_Array=StringSplit($s_cumulate,"|")
ConsoleWrite($Message & "=" & UBound($ar_Array) - 1 & @TAB & " _FileListToArrayRecurse3 " & @TAB & _
        ":" & @TAB & Round(TimerDiff($timerstamp1)) & "" & @TAB & " msec" & @LF)
_ArrayDisplay($ar_Array,"Results"& Round(TimerDiff($timerstamp1)) & "" & @TAB & " msec")
Best, Randall Edited by randallc

Share this post


Link to post
Share on other sites

Can somebody please submit _FileListToArrayEx() to standard include files?

I'm missing recurse file/directory listing functionality in standard AutoIt very much.

I still use very old _FileSearch() for that purpose.

I don't know if SmOke_N or Randallc has better solution

but I noticed Randallc's version uses ObjCreate("Scripting.Dictionary") which is incompatible with older Windows

so SmOke_N's is probably better candidate by me.

Header could be:

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $iRecurse = False, $iBaseDir = 1, $sExclude = '')
Edited by Zedna

Share this post


Link to post
Share on other sites

Can somebody please submit _FileListToArrayEx() to standard include files?

I'm missing recurse file/directory listing functionality in standard AutoIt very much.

I still use very old _FileSearch() for that purpose.

I don't know if SmOke_N or Randallc has better solution

but I noticed Randallc's version uses ObjCreate("Scripting.Dictionary") which is incompatible with older Windows

so SmOke_N's is probably better candidate by me.

Header could be:

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $iRecurse = False, $iBaseDir = 1, $sExclude = '')
He'll have to submit it to a Dev, and It'll get looked at and possibly added in.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Hi,

Mine still needs more thorough checking, i think, but does not have the DOS problem of incorrect filenames if containing foreign characters (ANSII>127?). I am not sure if that has been fixed in DOS in Vista, but certainly is a problem in Win 9x and XP.

I only just changed the duplicate removal to use scripting object, which it did not use before version 2j; in win9x , it just means any duplicates would have to be removed manually afterwards... or you could help and rewrite the duplicate removal function! (even as it stands, it does not crash Win9x, and only might return dupes if more than one wildcard, and not mutually exclusive anyway.)

An easy way would be to add a dupe removal function depending on version; but it did not seem worth it.. (the only ones I have seen that are reliable are really slow; my first attempt was faster, but sometimes one short as the algorithm needed fixing; and way slower than dictionary object.)

Best, randall

Share this post


Link to post
Share on other sites

Hi,

Mine still needs more thorough checking, i think, but does not have the DOS problem of incorrect filenames if containing foreign characters (ANSII>127?). I am not sure if that has been fixed in DOS in Vista, but certainly is a problem in Win 9x and XP.

That's very BAD issue!!

Then it would be better to make final _FileListToArrayEx() as merge of SmOke_N and Randallc version

using FileFindFirst/FileFindNext instead of DOS DIR.

I only just changed the duplicate removal to use scripting object, which it did not use before version 2j; in win9x , it just means any duplicates would have to be removed manually afterwards... or you could help and rewrite the duplicate removal function! (even as it stands, it does not crash Win9x, and only might return dupes if more than one wildcard, and not mutually exclusive anyway.)

An easy way would be to add a dupe removal function depending on version; but it did not seem worth it.. (the only ones I have seen that are reliable are really slow; my first attempt was faster, but sometimes one short as the algorithm needed fixing; and way slower than dictionary object.)

Best, randall

I think that remove duplicates needn't be in such general purpose standard UDF _FileListToArrayEx().

This _FileListToArrayEx() should be mainly for recursive listing of files/directories

Removing duplicates is particular Array problem which could be solved on output array

by some specialized array function: _ArrayRemoveDuplicates().

Edited by Zedna

Share this post


Link to post
Share on other sites

In the SmOke_N version the problem with DOS 'foreign' chars is simply due to DOS using OEM codepage.

So the solution is simple. Translate filenames from Oem To Ansi.

...
        Local $a_AnsiFName = DllCall('user32.dll','Int','OemToChar','str',$aFSplit[$iCC],'str','')
        If @error=0 Then $aFSplit[$iCC] = $a_AnsiFName[2]
...oÝ÷ Ù«­¢+ÙÕ¹}¥±1¥ÍÑQ½ÉÉåà ÀÌØíÍAÑ °ÀÌØíÍ¥±ÑÈôÌä쨸¨Ìäì°ÀÌØí¥±ôÀ°ÀÌØíÍá±ÕôÌäìÌäì°ÀÌØí¥IÕÉÍô±Í¤(%9½Ð¥±á¥ÍÑÌ ÀÌØíÍAÑ ¤Q¡¸IÑÕɸMÑÉÉ½È Ä°Ä°ÌäìÌäì¤(%ÀÌØíÍ¥±ÑÈô´Ä=ÈÀÌØíÍ¥±ÑÈôÕ±ÐQ¡¸ÀÌØíÍ¥±ÑÈôÌä쨸¨Ìäì(%ÀÌØí¥±ô´Ä=ÈÀÌØí¥±ôÕ±ÐQ¡¸ÀÌØí¥±ôÀ(%ÀÌØíÍá±Õô´Ä=ÈÀÌØíÍá±ÕôÕ±ÐQ¡¸ÀÌØíÍá±ÕôÌäìÌäì(1½°ÀÌØí 
¡ÉlÙtôlÌäìÀäÈìÌäì°Ìäì¼Ìäì°ÌäìèÌäì°ÌäìÐìÌäì°Ìäì±ÐìÌäì°ÌäíðÌäít(ÀÌØíÍ¥±ÑÈôMÑÉ¥¹IáÁIÁ± ÀÌØíÍ¥±ÑÈ°ÌäìÀäÈį́ìÀäÈį́Ìäì°ÌäììÌäì¤(%MÑÉ¥¹I¥¡Ð ÀÌØíÍAÑ °Ä¤±ÐìÐìÌäìÀäÈìÌäìQ¡¸ÀÌØíÍAÑ µÀìôÌäìÀäÈìÌäì(½ÈÀÌØí¥
ôÀQ¼Ô(%MÑÉ¥¹%¹MÑÈ ÀÌØíÍ¥±ÑÈ°ÀÌØí   
¡ÉlÀÌØí¥

t¤=È|(MÑÉ¥¹%¹MÑÈ ÀÌØíÍá±Õ°ÀÌØí    
¡ÉlÀÌØí¥

t¤Q¡¸IÑÕɸMÑÉÉ½È È°È°ÌäìÌäì¤(9áÐ(%MÑÉ¥¹MÑÉ¥Á]L ÀÌØíÍ¥±ÑÈ°à¤ôÌäìÌäìQ¡¸IÑÕɸMÑÉÉ½È È°È°ÌäìÌäì¤(%9½Ð ÀÌØí¥±ôÀ=ÈÀÌØí¥±ôÄ=ÈÀÌØí¥±ôȤQ¡¸IÑÕɸMÑÉÉ½È Ì°Ì°ÌäìÌäì¤(1½°ÀÌØí½M

Share this post


Link to post
Share on other sites

Would there be a way to make this only return the files name and no the entire file path?

For example: document.txt instead of C:\Documents and Settings\document.txt...

I know I could easily just trim the entire path into the name but it would be more efficient to originally gather just the file names.

Share this post


Link to post
Share on other sites

Would there be a way to make this only return the files name and no the entire file path?

For example: document.txt instead of C:\Documents and Settings\document.txt...

I know I could easily just trim the entire path into the name but it would be more efficient to originally gather just the file names.

What is so difficult with you writing a wrapper than having the developer re-write his entire function to fit your needs?
Func _FileListToArrayWrapperEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    $a_list = _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If @error Then Return SetError(@error, 0, 0)
    ;Short version without the proper _PathSplit
    For $i = 1 To $a_list[0]
        $a_list[$i] = StringTrimLeft($a_list[$i], StringInStr($a_list[$i], "\", 1, -1))
    Next
    Return $a_list
EndFunc
30 seconds of work.

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.

Share this post


Link to post
Share on other sites

hi

srry for the bump

i want to search folders in all subdirectories, and all subdirectories within those directories until there are no more directories to search

when i find them i want to delete the empty ones

this is my code:

#Include <File.au3>
#Include <Array.au3>

$ddnumber=0

$FileList=_FileListToArray(FileSelectFolder("Delete Empty directories from:", @desktopdir))
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

for $i = 1 to $FileList[0]
    if StringInStr(FileGetAttrib($FileList[$i]),"D") Then
        if DirGetSize($FileList[$i]) = 0 Then
            if DirRemove($FileList[$i]) then 
                ConsoleWrite("Dir removed: " & $FileList[$i] & @crlf)
                $ddnumber +=1
            Else
                ConsoleWrite("Could not remove (empty?) dir: " & $FileList[$i] & @crlf)
            endif
        Else
            ConsoleWrite("Dir not removed (contains files): " & $FileList[$i] & @crlf)
        endif
    EndIf
Next


If $ddnumber=0 Then
    msgbox(0,"No empty directories", "No empty directories found")
Else
    MsgBox(0,"Results", $ddnumber & " empty directories removed")
EndIf

what adjustments can i make to the code to include all subdirectories and all other folders?

currently it only affects chosen directory only, and does not search within any other folders to find other empty ones

sorry to sound like a noob but i am quite new to autoit

current code thanks to KaFu


Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

Changed the code a bit, a friend noted strange behavior with exclude:

I'll update the first post the next time I revisit this link:

Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $i_recurse = 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 & '*.*"'
    
    ; Collect file data
    Local $i_pid, $s_stdout, $s_hold_out
    If $i_recurse Then
        $i_pid = Run(@ComSpec & " /c dir /b /s /a " & $s_hold_split, "", @SW_HIDE, 4 + 2)
    Else
        $i_pid = Run(@ComSpec & " /c dir /b /a " & $s_hold_split, "", @SW_HIDE, 4 + 2)
    EndIf
    
    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)" & $s_exclude) Then ContinueLoop
        If StringRegExp($a_fsplit[$i], "^\w:[\\/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i]
        
        If $i_flag = 0 Then
            $s_hold_ret &= $a_fsplit[$i] & Chr(1)
        ElseIf $i_flag = 1 And StringInStr(FileGetAttrib($a_fsplit[$i]), "d") = 0 Then
            $s_hold_ret &= $a_fsplit[$i] & Chr(1)
        ElseIf $i_flag = 2 And StringInStr(FileGetAttrib($a_fsplit[$i]), "d") Then
            $s_hold_ret &= $a_fsplit[$i] & 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

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.

Share this post


Link to post
Share on other sites

hi

srry for the bump

i want to search folders in all subdirectories, and all subdirectories within those directories until there are no more directories to search

when i find them i want to delete the empty ones

this is my code:

#Include <File.au3>
#Include <Array.au3>

$ddnumber=0

$FileList=_FileListToArray(FileSelectFolder("Delete Empty directories from:", @desktopdir))
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

for $i = 1 to $FileList[0]
    if StringInStr(FileGetAttrib($FileList[$i]),"D") Then
        if DirGetSize($FileList[$i]) = 0 Then
            if DirRemove($FileList[$i]) then 
                ConsoleWrite("Dir removed: " & $FileList[$i] & @crlf)
                $ddnumber +=1
            Else
                ConsoleWrite("Could not remove (empty?) dir: " & $FileList[$i] & @crlf)
            endif
        Else
            ConsoleWrite("Dir not removed (contains files): " & $FileList[$i] & @crlf)
        endif
    EndIf
Next


If $ddnumber=0 Then
    msgbox(0,"No empty directories", "No empty directories found")
Else
    MsgBox(0,"Results", $ddnumber & " empty directories removed")
EndIf

what adjustments can i make to the code to include all subdirectories and all other folders?

currently it only affects chosen directory only, and does not search within any other folders to find other empty ones

sorry to sound like a noob but i am quite new to autoit

current code thanks to KaFu

Your code isn't using my function/udf. Recursive search is standard with mine. In the above post you'll see a re-write of it. The instructions are still in the first post.

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.

Share this post


Link to post
Share on other sites

Another update, added extra param for just file/dir name without full path. Should be even faster still now. (a param has been added, please look at the params to get an idea what to pass to what)

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)" & $s_exclude) 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
I'll update the first post... when I get a chance :) 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.

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  

×
×
  • Create New...