asgarcymed Posted October 2, 2007 Share Posted October 2, 2007 Inside a main directory I have many files, and I want to get a list of all files that simultaneously have the PDF extension (*.pdf) AND name beginning by an "A" (A*). Or either, I am trying to use a filter that has more than one component. I could make 2 different scripts that use a filter with one-only component: CODE$path = "C:\Test" $filter = "*.pdf" $search = FileFindFirstFile ($path & "\" & $filter) While $search = 1 $file = FileFindNextFile ($search) If @error Then ExitLoop MsgBox (0, "File Name", $file) WEnd CODE#Include <File.au3> #Include <Array.au3> $path = "C:\Test" $filter = "*.pdf" $file_list = _FileListToArray ($path, $filter) _ArrayDisplay ($file_list, "File List") I tried $filter = "A*" And "*.pdf" But I got an error.... How can I use a filter that has more than one component? Thanks in advance. Best regards. MLMK - my blogging craziness... Link to comment Share on other sites More sharing options...
Nahuel Posted October 2, 2007 Share Posted October 2, 2007 I don't know about using multiple filters. It is possible with other functions, like "FileOpenDialog" but it doesn't seem to work here. Anyway, try this: #include <File.au3> #include <Array.au3> $path = "C:\Test" $filter = "*.pdf" $search = _FileListToArray($path,$filter) If IsArray($search) Then For $i=0 to $search[0] If StringLeft($search[$i],1)="A" Then MsgBox(0,"",$search[$i]) EndIf Next Else MsgBox(0,"Error","No files found") EndIf Link to comment Share on other sites More sharing options...
randallc Posted October 2, 2007 Share Posted October 2, 2007 Hi, Try link in my sig to new proposed _FileListToArray; #include<_FileListToArrayNew2g.au3> local $path = @ScriptDir,$filter = "*.txt|A*" $ar_Array = _FileListToArray3 ($path, $filter, 1, 0, 0) _ArrayDisplay($ar_Array, "File List")Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
asgarcymed Posted October 3, 2007 Author Share Posted October 3, 2007 (edited) randallc - If I use: $filter = "A*|*.pdf" or $filter = "A*"|"*.pdf" I get the same error - @Error = 2 (Invalid $sFilter) And if I write: #include <_FileListToArrayNew2g.au3> I get another error message - " ==> Error opening the file.: <_FileListToArrayNew2g.au3> Nahuel - your code works fine! Thank you! But how to do in order to use, for example, a filter with 4 components? Filter_with_4_conditions = ((filename with the "A*" wildcard) AND (filename with the "*.pdf" wildcard) AND 10 < StringLen (filename) <22) AND (FileGetSyze > 4 MB)) I am trying to code a File Sorter by many parameters I specify... Forgive my late post but I had a problem in my home and only now I am near my computer again. Your answer was very quick; thanks! Please do not abandon this question.... Thanks in advance! Edited October 3, 2007 by asgarcymed MLMK - my blogging craziness... Link to comment Share on other sites More sharing options...
Nahuel Posted October 3, 2007 Share Posted October 3, 2007 #include <_FileListToArrayNew2g.au3>I get another error message - " ==> Error opening the file.: <_FileListToArrayNew2g.au3>You need to dowload that file:http://www.autoitscript.com/forum/index.ph...mp;#entry372868save it in the Include folder in the AutoIt directory and try again. I think randallc's script works fine Link to comment Share on other sites More sharing options...
asgarcymed Posted October 3, 2007 Author Share Posted October 3, 2007 Now the script runs fine but the search results are not correctly restricted to the filters... Files must have its name beginning with an "A" (filter 1 = "A*" wildcard") and its extension (last letters after the last dot) must be txt (filter 2 = "*.txt" wildcard). I even tried (again; now with the new include file) - $filter = "A*|*.pdf" (no error messages but the list is much bigger / inaccurate) vs $filter = "A*"|"*.pdf" (got error message - ==> Unable to parse line.: ). It seems that this new file included <_FileListToArrayNew2g.au3> may have a bug; or it is my brain buggy? Thanks for replying MLMK - my blogging craziness... Link to comment Share on other sites More sharing options...
randallc Posted October 3, 2007 Share Posted October 3, 2007 (edited) Now the script runs fine but the search results are not correctly restricted to the filters... Files must have its name beginning with an "A" (filter 1 = "A*" wildcard") and its extension (last letters after the last dot) must be txt (filter 2 = "*.txt" wildcard). I even tried (again; now with the new include file) - $filter = "A*|*.pdf" (no error messages but the list is much bigger / inaccurate) vs $filter = "A*"|"*.pdf" (got error message - ==> Unable to parse line.: ). It seems that this new file included <_FileListToArrayNew2g.au3> may have a bug; or it is my brain buggy?Thanks for replying OK thanks,I'll have a look; did you try the way I had tested?; "*.txt|A*"?Thanks, Randall Edited October 3, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Nahuel Posted October 3, 2007 Share Posted October 3, 2007 $filter = "A*"|"*.pdf" (got error message - ==> Unable to parse There's your mistake. It should be: $filter = "A*|*.txt" But you're right, it doesn't work... I suppose you could just add more conditions to the code I gave you before... I don't know, just an idea.. #include <File.au3> #include <Array.au3> $path = "C:\" $filter = "*.ini" $search = _FileListToArray($path,$filter) If IsArray($search) Then For $i=0 to $search[0] If StringLeft($search[$i],1)="A" Then If (10>StringLen($search[$i])) And (StringLen($search[$i])>20) Then MsgBox(0,"",$search[$i]) EndIf EndIf Next Else MsgBox(0,"Error","No files found") EndIf Link to comment Share on other sites More sharing options...
randallc Posted October 4, 2007 Share Posted October 4, 2007 (edited) $filter = "A*|*.txt" But you're right, it doesn't work...Hi, Maybe rem out this line till I think about it! - It works again this way.. [about line 47 in UDF] ;~ $sFilter = StringReplace("*" & $sFilter & "*", "**", "*")Best, randall [PS You can be more specific also if you use ArraySearch, arrayFindAll - 1helpfile, 2search ultima] Edited October 4, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
asgarcymed Posted October 6, 2007 Author Share Posted October 6, 2007 After many hours of brain working, I could improve my knowledge a lot! And the help you gave me was very, very important! So I want to "say louder" - THANK YOU!!! MLMK - my blogging craziness... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now