Jump to content



Photo

_FileListToArrayEx

_regenumkeyex _filelisttoarrayex array udf file search

  • Please log in to reply
39 replies to this topic

#1 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 27 July 2011 - 10:38 PM

Hi All, Sorry for my English

AutoIt         
#include-once ; #UDF# ======================================================================================================================= ; Title .........: File List To Array ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _FileListToArrayEx ; =============================================================================================================================== ; #FUNCTION# ======================================================================================================================================================= ; Name...........: _FileListToArrayEx ; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax.........: _FileListToArrayEx($sPath[, $sFilter = "*"[, $iFlag = 0]]) ; Parameters ....: $sPath   - Path to generate filelist for. ;                 $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details. ;                 $iFlag   - Optional: specifies whether to return files folders or both Or Full Path (add the flags together for multiple operations): ;                 |$iFlag = 0 (Default) Return both files and folders ;                 |$iFlag = 1 Return files only ;                 |$iFlag = 2 Return Folders only ;                 |$iFlag = 4 Search SubDirectory ;                 |$iFlag = 8 Return Full Path ;                 |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ;                 |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ;                   By Default the first element ($array[0]) contains the number of file found, the remaining elements ($array[1], $array[2], etc.) ;                 |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp (Can not be combined with flag 16) ;                 |$iFlag = 128 Return Backslash at the beginning of the file name, example Return "\Filename1.xxx" (Can not be combined with flag 8) ; Return values .: Failure - @Error ;                 |1 = Path not found or invalid ;                 |2 = Invalid $sFilter ;                 |3 = No File(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: 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 ; Related .......: ; Link ..........: ; Example .......: Yes ; Note ..........: Special Thanks to SolidSnake & Tlem ; ================================================================================================================================================================== Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0)     $sPath = StringRegExpReplace($sPath & "\", "(?!\A)[\\/]+\h*", "\\")     If Not FileExists($sPath) Then Return SetError(1, 1, "")     If StringRegExp($sFilter, StringReplace('^\s*$|\v|[\\/:><"]|^\||\|\||\|$', "[" & Chr(BitAND($iFlag, 64) + 28) & '\/:><"]|^\||\|\||\|$', "\\\\")) Then Return SetError(2, 2, "")     Local $hSearch, $sFile, $sFileList, $sSubDir = BitAND($iFlag, 4), $sDelim = "|", $sDirFilter = StringReplace($sFilter, "*", "")     $hSearch = FileFindFirstFile($sPath & "*")     If @Error Then Return SetError(3, 3, "")     Local $hWSearch = $hSearch, $hWSTMP, $SearchWD, $Extended, $iFlags = StringReplace(BitAND($iFlag, 1) + BitAND($iFlag, 2), "3", "0")     If BitAND($iFlag, 8) Then $sDelim &= $sPath     If BitAND($iFlag, 128) Then $sDelim = "|\"     If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")"     While 1         $sFile = FileFindNextFile($hWSearch)         If @Error Then             If $hWSearch = $hSearch Then ExitLoop             FileClose($hWSearch)             $hWSearch -= 1             $SearchWD = StringLeft($SearchWD, StringInStr($SearchWD, "\", 1, -2))         ElseIf $sSubDir Then             $Extended = @Extended             If ($iFlags + $Extended <> 2) Then                 If $sDirFilter Then                     If StringRegExp($sFile, $sFilter) Then $sFileList &= $sDelim & $SearchWD & $sFile                 Else                     $sFileList &= $sDelim & $SearchWD & $sFile                 EndIf             EndIf             If Not $Extended Then ContinueLoop             $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "\*")             If $hWSTMP = -1 Then ContinueLoop             $hWSearch = $hWSTMP             $SearchWD &= $sFile & "\"         Else             If ($iFlags + @Extended = 2) Or StringRegExp($sFile, $sFilter) = 0 Then ContinueLoop             $sFileList &= $sDelim & $sFile         EndIf     WEnd     FileClose($hSearch)     If Not $sFileList Then Return SetError(3, 3, "")     Return StringSplit(StringTrimLeft($sFileList, 1), "|", StringReplace(BitAND($iFlag, 32), "32", 2)) EndFunc    ;==>_FileListToArrayEx


Registry Key List To Array - Read Registry Key\SybKey _RegEnumKeyEx

Attached Files


Edited by DXRW4E, 25 January 2013 - 04:04 PM.

  • VelvetElvis likes this





#2 llewxam

llewxam

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 345 posts

Posted 19 November 2011 - 05:39 PM

Wow, very nice! Thanks for sharing!

Ian
  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized siteagent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.

#3 1234hotmaster

1234hotmaster

    Seeker

  • Active Members
  • 13 posts

Posted 04 January 2012 - 11:56 AM

Nice share! Thanks :)

#4 jixiren001

jixiren001

    Seeker

  • Normal Members
  • 2 posts

Posted 12 January 2012 - 01:45 PM

Nice ! Thanks !

#5 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 21 January 2012 - 08:14 AM

@All
Thanks

Updated
Added Multiple filter groups, look at the first post

Ciao.

Edited by DXRW4E, 21 January 2012 - 08:14 AM.


#6 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,811 posts

Posted 21 January 2012 - 08:47 AM

Related
_FileListToArrayEx
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#7 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 21 January 2012 - 09:00 AM

Perhaps a Developers, Moderator, MVP or other, perhaps need to review this (see if need anything else to repair improve something or other), and perhaps use this to defualt (and the same code, the one defined by default, only it was updated), as it seems that the code more clean (39 line) and I think works faster, so maybe it also closes the history of _FileListToArray + Search subdirectory

sorry for my English

Ciao a tutti.

Edited by DXRW4E, 21 January 2012 - 09:03 AM.


#8 Tlem

Tlem

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 279 posts

Posted 22 January 2012 - 03:55 PM

@JohnOne
The SmOke_N FileListToArrayEx function presents two problems with regard to that of the DXRW4E :
1st : She's more slowly (we talk about some ms, so it's not really important)
2nd : The return are not true, because if I search for this _FileListToArrayEx2(@WindowsDir, "*.dll", 1), it return me files like this C:WINDOWSInstaller$PatchCache$Managed5C1093C35543A0E32A41B090A305076A4.0.30319system.net.dll_x86

Edited by Tlem, 22 January 2012 - 03:56 PM.

Best Regards.Thierry

#9 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 23 January 2012 - 01:31 PM

@JohnOne
The SmOke_N FileListToArrayEx function presents two problems with regard to that of the DXRW4E :
1st : She's more slowly (we talk about some ms, so it's not really important)
2nd : The return are not true, because if I search for this _FileListToArrayEx2(@WindowsDir, "*.dll", 1), it return me files like this C:WINDOWSInstaller$PatchCache$Managed5C1093C35543A0E32A41B090A305076A4.0.30319system.net.dll_x86


Hmm, that's an expected return. That is a mask search, not an extension search.

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.


#10 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 23 January 2012 - 01:57 PM

as it seems that the code more clean (39 line) and I think works faster, so maybe it also closes the history of _FileListToArray + Search subdirectory

Not trying to pick on you.. but you cant call it 39 lines, or call it clean when you have a line like this in your code:
Local $hWSearch = $hSearch, $hWSTMP = $hSearch, $SearchWD, $FPath = StringRegExpReplace(StringRegExpReplace($sSDir, '[^2]+', ""), "2+", StringRegExpReplace($sPath, '\\', "\\\\")), $sSDirF[3] = [0, StringReplace($sSDirFTMP, "*", ""), "(?i)(" & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace("|" & $sSDirFTMP & "|", '\|\h*\|[\|\h]*', "\|"), '[\^\$\(\)\+\[\]\{\}\,\.\=]', "\\$0"), "\|([^\*])", "\|^$1"), "([^\*])\|", "$1\$\|"), '\*', ".*"), '^\||\|$', "") & ")"]


#11 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 23 January 2012 - 02:07 PM

Hi Beege, that's not a problem is called only once, and it is a necessary thing, the_FileListToArrayEx uses only 1 While, more clean so I do not think that there is

and sorry for my English

Ciao.

#12 Tlem

Tlem

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 279 posts

Posted 23 January 2012 - 07:51 PM

Hmm, that's an expected return. That is a mask search, not an extension search.

Sorry, but I can't be agree with you. Make a try with the Windows search. If you search for this mask *.dll the result never return files like system.net.dll_x86.

If I want to search for these files, I use this mask : *.dll*
So for me, it can't be an expected return.

Edited by Tlem, 23 January 2012 - 07:51 PM.

Best Regards.Thierry

#13 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,797 posts

Posted 09 February 2012 - 06:23 PM

There's a problem in this function. Your $sDir parameter has incorrect information in the header, it states:

; $sSDir - Optional: specifies whether to return files folders or both
; |$sSDir=1 Search subdirectory
; |$sSDir=2 Search subdirectory & Return Full Path

But inside the function itself, it doesn't look at whether $sSDir is 1 or 2, it returns the same results regardless of what you set $sSDir to, unless you set it to 0.

        ElseIf $sSDir Then

That line only checks if it's True (not 0) or False (0). This follows the default parameter of the function where you set $sSDir=0.


I did some further testing and found out I was incorrect in my original assumption. The problem actually isn't that 1 and 2 for the $sSDir parameter return the same results, because they don't they return different results I just had made an error in my test script. The problem is that the $sSDir parameter takes a third option that's not mentioned, which is 0, which tells the script to not do a recursive search in the target folder. My apologies for that, but the header information is still missing that point, but definitely not a bug in this UDF.


EDIT:Corrected wrong information in my original post.

Edited by BrewManNH, 09 February 2012 - 07:40 PM.

How to ask questions the smart way!

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.

Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.

_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#14 FVN

FVN

    Seeker

  • New Members
  • 2 posts

Posted 04 April 2012 - 04:51 PM

Hi,
I can't figure out a way to obtain non-recursive & fullpath result, instead of the non-recursive & filename only result (obtained through built-in parameter $sSDir=0).
Could someone help me please ?

#15 Tlem

Tlem

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 279 posts

Posted 04 April 2012 - 08:50 PM

If you search files (or subdirectory) in a specific directory without the recursive option, why did you need to store the path ???
You know it, so it's easy to add it on your result :
#include "_FileListToArrayEx.au3" $Path = "C:" $aArray = _FileListToArrayEx($Path, "*", 1, 0) For $i = 1 To UBound($aArray) - 1 ConsoleWrite($Path & $aArray[$i] & @CRLF) Next


EDIT : But I agree with you, DXRW4E would have been able to separate the recursive option and the return of full path. ;)

Edited by Tlem, 04 April 2012 - 08:59 PM.

Best Regards.Thierry

#16 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 05 April 2012 - 12:31 AM

I did not want to change the original code, that and the setting and the original code for this reason the left so

However who wants to will be able to modify the code if they suffered, just put it so
$FPath = StringRegExpReplace(StringRegExpReplace($sSDir, '[^2]+', ""), "2+", StringRegExpReplace($sPath, '\\', "\\\\"))
in
$FPath = $sPath

So Default and always full path (no need to use more $sSDir = 2)

Sorry for my english

Edited by DXRW4E, 05 April 2012 - 12:35 AM.


#17 FVN

FVN

    Seeker

  • New Members
  • 2 posts

Posted 05 April 2012 - 02:31 PM

Thank you both for your feed-back

@TIem: I'm looking for files in a list of directories (specified in an XML file) ; each of these directories has a recursivity search boolean param. I thought about your solution, but it seemed to me more convenient and elegant to change the _FileListToArrayEx behaviour itself.
At the end of the day, I'm able to implement your proposal, because it's so easy.

@DRXW4E: I'm afraid I do not understand where to implement this or these new lines of code (not because of your english!). So, I'm going to adopt TIen proposal, except if you were so kind to indicate more clearly where to put this code excatly in the function, or even, separate recursitvity param from full path param, as stated by TIem.

Bye,

#18 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 05 April 2012 - 05:07 PM

First post of topics and code of _FileListToArrayEx.au3, Replace the line shown in post above, after _FileListToArrayEx.au3 always return full path

Ciao.

#19 Tlem

Tlem

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 279 posts

Posted 05 April 2012 - 08:33 PM

@DXRW4E
Your proposition doesn't work for root directory. You must modifie this part too
$sFileList &= $sDelim & $sFile
by
$sFileList &= $sDelim & $FPath & $sFile


I understand why you doesn't want make more modification on your function, but in my opinion, the recursive search and full path return must be a separate option.
To take care about what BrewManNH said about the $sSDir flag 0 and what FVn ask, this is my adaptation of your function :
AutoIt         
#include-once ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #FUNCTION# ==================================================================================================================== ; Name...........: _FileListToArrayEx ; Description ...: Lists files andor folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax.........: _FileListToArrayEx($sPath[, $sFilter = "*"[, $iFlag = 0 [, $iSDir = 0 [, $iFPath = 1]]]]) ; Parameters ....: $sPath   - Path to generate filelist for. ;                 $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details. ;                 $iFlag   - Optional: specifies whether to return files folders or both ;                   |$iFlag=0 (Default) Return both files and folders ;                   |$iFlag=1 Return files only ;                   |$iFlag=2 Return Folders only ;                 $iSDir   - Optional: specifies whether to return files folders or both ;                   |$iSDir=0 Do not Search subdirectory (default) ;                   |$iSDir=1 Search subdirectory ;                 $iFPath  - Optional: specifies whether to return files folders or both ;                   |$iFPath=0 Do not return full path ;                   |$iFPath=1 Return full path (Default) ; Return values .: @Error ;     |1 = Path not found or invalid ;                   |2 = Invalid $sFilter ;                   |3 = Invalid $iFlag ;                   |4 = No File(s) Found ; Author ........: SolidSnake <metalgx91 at="" gmail="" dot="" com=""> ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ;                               $array[0] = Number of FilesFolders returned ;                               $array[1] = 1st FileFolder ;                               $array[2] = 2nd FileFolder ;                               $array[3] = 3rd FileFolder ;                               $array[n] = nth FileFolder ; Related .......: ; Link ..........: <a href='http://www.autoitscript.com/forum/topic/131277-filelisttoarrayex' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/131277-filelisttoarrayex</a> ; Example .......: Yes ; Note ..........: Special Thanks to Helge and Layer for help with the $iFlag update speed optimization by code65536, pdaughe ;                 Update By DXRW4E ;                 Update By Tlem ; =============================================================================================================================== Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0, $iSDir = 0, $iFPath = 1) Local $hSearch, $sFile, $sFileList, $sDelim = "|", $sSDirFTMP = $sFilter, $FPath $sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing backslash If Not FileExists($sPath) Then Return SetError(1, 1, "") If StringRegExp($sFilter, "[/:><]|(?s)As*z") Then Return SetError(2, 2, "") If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "") $hSearch = FileFindFirstFile($sPath & "*") If @error Then Return SetError(4, 4, "") If $iFPath = 1 Then $FPath = $sPath Local $hWSearch = $hSearch, $hWSTMP = $hSearch, $SearchWD, $sSDirF[3] = [0, StringReplace($sSDirFTMP, "*", ""), "(?i)(" & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace("|" & $sSDirFTMP & "|", '|h*|[|h]*', "|"), '[^$()+[]{},.=]', "$0"), "|([^*])", "|^$1"), "([^*])|", "$1$|"), '*', ".*"), '^|||$', "") & ")"] While 1   $sFile = FileFindNextFile($hWSearch)   If @error Then    If $hWSearch = $hSearch Then ExitLoop    FileClose($hWSearch)    $hWSearch -= 1    $SearchWD = StringLeft($SearchWD, StringInStr(StringTrimRight($SearchWD, 1), "", 1, -1))   ElseIf $iSDir Then    $sSDirF[0] = @extended    If ($iFlag + $sSDirF[0] <> 2) Then     If $sSDirF[1] Then      If StringRegExp($sFile, $sSDirF[2]) Then $sFileList &= $sDelim & $FPath & $SearchWD & $sFile     Else      $sFileList &= $sDelim & $FPath & $SearchWD & $sFile     EndIf    EndIf    If Not $sSDirF[0] Then ContinueLoop    $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "*")    If $hWSTMP = -1 Then ContinueLoop    $hWSearch = $hWSTMP    $SearchWD &= $sFile & ""   Else    If ($iFlag + @extended = 2) Or StringRegExp($sFile, $sSDirF[2]) = 0 Then ContinueLoop    $sFileList &= $sDelim & $FPath & $sFile   EndIf WEnd FileClose($hSearch) If Not $sFileList Then Return SetError(4, 4, "") Return StringSplit(StringTrimLeft($sFileList, 1), "|") EndFunc   ;==>_FileListToArrayEx

Edited by Tlem, 05 April 2012 - 08:35 PM.

Best Regards.Thierry

#20 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 06 April 2012 - 12:17 AM

@Tlem
Hi Tlem, Thank You, you're right, or forget that the full path is used only for subdir

to be honest I do not like much the fate of using many flags in a function (I mean best to use as little as possible, BITAND and really nice), I think the better way and what he or posted in first post

However who like that way will be able to use your script (that is already OK) in post above (_FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0, $iSDir = 0, $iFPath = 1)), so I think everything is OK

Many Thanks Again

@FVN
Now you can use for example
$iFlag = 0 + 8 --> Return both files and folders and Full Path
Or
$iFlag = 0 + 8 + 4 --> Return both files and folders and subdirectory and Full Path
Or
$iFlag = 1 + 8 + 4 --> Return files only and subdirectory and Full Path
Or
$iFlag = 1 + 8 --> Return files only and Full Path
ect ect ect ect

@All
already updated the first post

sorry again for my English

Ciao.

Edited by DXRW4E, 06 April 2012 - 03:56 AM.






Also tagged with one or more of these keywords: _regenumkeyex, _filelisttoarrayex, array, udf, file, search

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users