Faalamva Posted January 22, 2014 Share Posted January 22, 2014 Hi, here's the deal : I have a directory D:Test in which I have more than 1700 subdirectories, all named 2013XXXXXXXX (the blurred parts may contain letters and figures) : I'd like to check that the main directory doesn't contain any 2014* subdirectories. I have written the following test program : $Folders = _FileListToArray("D:\Test\", "2014*", 2) MsgBox(0, "", $Folders[0]) For $i = 1 To $Folders[0] ConsoleWrite($i & " : " & $Folders[$i] & @CRLF) Next Strangely, the MsgBox returns 5 occurrences found ! And the list returned is something like : 1 : 20130521_214630_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 2 : 20130330_110444_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 3 : 20130331_111940_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 4 : 20130117_194957_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 : 20130407_172611_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX These occurrences don't begin with 2014 (and don't contain 2014 either). So it seems the 2014* filter doesn't work properly, or am I missing something ? Thanks ! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 22, 2014 Moderators Share Posted January 22, 2014 Faalamva,As mentioned in the Help file, _FileListToArray uses Windows to search for files and it has been shown that wildcards can sometimes return strange results. Please try using _FileListToArrayRec (without the recur flag) as that uses a RegEx to search and is a little more strict in its wildcard observance - albeit at the cost of speed. Perhaps that will do better: $Folders = _FileListToArrayRec("D:\Test\", "2014*", 2) MsgBox(0, "", $Folders[0]) For $i = 1 To $Folders[0] ConsoleWrite($i & " : " & $Folders[$i] & @CRLF) NextLet me know how you get on - I do not really want to have to create 1700 folders to test it myself. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
orbs Posted January 22, 2014 Share Posted January 22, 2014 @Faalamva, for your specific purpose, try this: If FilesExist('D:\test\2014*') Then MsgBox(0,'result:','found file(s) or folder(s).') Else MsgBox(0,'result:','did not find file(s) or folder(s).') EndIf Func FilesExist($sMask) Local $hSearch=FileFindFirstFile($sMask) Local $sFile $sFile=FileFindNextFile($hSearch) If @error Then Return False Else Return True EndIf EndFunc that is my take on FileExists() which i always ranted about it not supporting wildcards... @Melba23: For $i=1 To 1700 DirCreate('D:\Test\2013_'&$i) Next :-) Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
BrewManNH Posted January 22, 2014 Share Posted January 22, 2014 _FileListToArray uses FileFindFirstFile and FileFindNextFile to find the files to put into the array, I don't think that snippet is going to do any better than the UDF. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. 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 editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 22, 2014 Moderators Share Posted January 22, 2014 (edited) orbs,That will not reproduce the OP's folder structure and so would be of no use at all. M23 Edited January 22, 2014 by Melba23 Speeling Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
orbs Posted January 22, 2014 Share Posted January 22, 2014 _FileListToArray uses FileFindFirstFile and FileFindNextFile to find the files to put into the array, I don't think that snippet is going to do any better than the UDF. true, but that snippet calls FileFindNextFile only once, while the UDF calls it repeatedly as long as there are any files out there that fit the mask. orbs, That will not reproduce the OP's folder structure and so would be of no use at all. M23 i was just kidding, i bet if you wanted to do that, it would take you about 13 seconds to script it - including power-on your pc, which takes ~12 of those seconds :-) Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Faalamva Posted January 22, 2014 Author Share Posted January 22, 2014 Thank you all for your replies. I have modified the script and run some tests. Note : First I had to figure out why _FileListToArrayRec couldn't be found despite the correct include. For those that may meet the same problem, just install AutoIt 3.3.10.1 (I was using the 3.3.8.1 version, which doesn't include _FileListToArrayRec natively in File.au3). So, here's the new script : #include <File.au3> $Folders = _FileListToArrayRec("D:\Test\", "2014*", 2) MsgBox(0, "", "@error returned is : " & @error) If @error = 9 Then MsgBox(0, "", "No occurrence found") Else MsgBox(0, "", $Folders[0]) For $i = 1 To $Folders[0] ConsoleWrite($i & " : " & $Folders[$i] & @CRLF) Next EndIf For some strange reason : - if I apply the 2013* mask, @error = 0 and all my folders are correctly returned. - if I apply the 2014* mask, @error = 1 and my program crashes (it's normal since $Folders[0] in this case is undefined). But I can't explain why @error = 1 ?? According to the help file, @error = 1 means "Path not found or invalid"... And I'm pretty positive that D:Test exists (tested with or without trailing ""...) ! Any thoughts ? Link to comment Share on other sites More sharing options...
Faalamva Posted January 22, 2014 Author Share Posted January 22, 2014 The previous code has also been tested on orbs' version of test directory, created by using : For $i=1 To 1700 DirCreate('D:\Test\2013_'&$i) Next The result is the same : - The filter 2014* returns @error = 1 !! - whereas the filter 2013* returns @error = 0 !! Link to comment Share on other sites More sharing options...
BrewManNH Posted January 22, 2014 Share Posted January 22, 2014 true, but that snippet calls FileFindNextFile only once, while the UDF calls it repeatedly as long as there are any files out there that fit the mask.Understandable, but what I was saying is that the filtering for _FLTA is the same as what you posted, so even if the OP were to use it with 2014* as the filter you'd get the same results as _FLTA. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. 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 editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 22, 2014 Moderators Share Posted January 22, 2014 Faalamva,You are confusing @error - which is set to 1 for all errors - and @extended - which in the "2014*" case is being set to 9 to indicate that no results were found, which is exactly what happens. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Solution Faalamva Posted January 22, 2014 Author Solution Share Posted January 22, 2014 (edited) Thank you Melba23 !! The code is finally working as expected ! #include <File.au3> $Folders = _FileListToArrayRec("D:\Test\", "2013*", 2) If @error = 1 And @extended <> 9 Then MsgBox(0, "", "An error occured : @extended = " & @extended) ElseIf @error = 1 And @extended = 9 Then MsgBox(0, "", "No folders found") ElseIf @error = 0 Then MsgBox(0, "", $Folders[0] & " occurrences found") EndIf Edited January 22, 2014 by Faalamva Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 22, 2014 Moderators Share Posted January 22, 2014 Faalamva,Glad we got it working. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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