Jump to content

Search the Community

Showing results for tags 'Circa summer 2009'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. I thought I'd post a recursive _FileListToArray() version that's approaching it's third birthday. It's one of the latter versions buried in Tlem's 263-post thread from June 2009: I don't claim authorship. Tlem started the ball rolling, contributing all along the way, many other members and about every MVP, MOD and even a couple DEV's had input in that thread. The function also draws from prior recursive _FileListToArray() versions. I do think it is still the most straight-forward version floating around, having all the most useful bells and whistles, and functions both efficiently and properly. It hasn't the "depth" or "sort" options available in the newer popular version by Melba23, but it offers a very concise single-function alternative. After nearly 3 years, I thought that something ought to be dug out of the obscurity of that massive thread (into which a lot of effort was invested by many) and placed where it's easier to find. This is identical to post 252 from the 2009 thread except the the function name is changed, the parameters are reordered to make it backward compatible with the production _FileListToArray, and the SRER escaping special characters, that used to have the comment " ; what other characters? ", is now complete. #include <Array.au3> #include <File.au3> $timer = TimerInit() $aArray = _FileListToArrayPlus(@WindowsDir, "s*.???.*", 1, "", "*.exe.*", 1, True) $timer = Round(TimerDiff($timer) / 1000, 2) & ' sec' _ArrayDisplay($aArray, $timer) Exit ; #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: False = Search $sPath folder only (default), True = Search $sPath and all subfolders ; Author ........: Half the AutoIt community (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) 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 ; tuned? 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 ; tuned? 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: Put the mysteriously disappearing "" back in. Thanks, agerrika & AZJIO Edit2: Correct all the missing backslashes.
×
×
  • Create New...