johnmcloud Posted February 3, 2012 Share Posted February 3, 2012 (edited) Hi guys, i have this simple script: #Include <File.au3> #Include <Array.au3> #include <RecFileListToArray.au3> ; External UDF $FileList=_RecFileListToArray(@Workingdir & "\Test", "*", 2, 1, 0, 2, "", "") ; Only Folder, all subfolder, full path 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) Else ConsoleWrite("Could not remove (empty?) dir: " & $FileList[$i] & @crlf) Endif Else ConsoleWrite("Not removed (contains files): " & $FileList[$i] & @crlf) Endif EndIf Next MsgBox(0,"Results", "Empty Removed") I have this problem. If i have a situation like this: EmptyDirMaster\EmptyDir\EmptyDir The array remove only the subfoder and don't the EmptyDirMaster. On ConsoleWrite i have: Could not remove (empty?) dir: Path\EmptyDirMaster If i start again it will delete the folder, but why don't process the first time? Thanks for support Edited February 4, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
hannes08 Posted February 3, 2012 Share Posted February 3, 2012 (edited) Hello johnmcloud, while you're looping your array the first subfolder get's deleted. The first one not because it's in the array before the subfolder: [0] = 3 [1] = C:temp [2] = C:tempDir1 So basically C:temp is not empty but 0 in size before C:tempDir1 get's deleted. Edit: By the way, why do you check whether your Path is a Directory ( StringInStr(FileGetAttrib($FileList[$i]),"D") ) id you're a) using _RecFileListToArray() with the "Folder only" function and DirRemove() ? Edited February 3, 2012 by hannes08 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
johnmcloud Posted February 3, 2012 Author Share Posted February 3, 2012 Hi Hannes, StringInStr(FileGetAttrib($FileList[$i]),"D") --> the force of habit How i can stop the loop? I don't know how many folder/subfolder it will be process Link to comment Share on other sites More sharing options...
johnmcloud Posted February 3, 2012 Author Share Posted February 3, 2012 (edited) #Include <File.au3> #Include <Array.au3> #include <RecFileListToArray.au3> ; External UDF $FileList = _RecFileListToArray(@Workingdir & "Test", "*", 2, 1, 0, 2, "", "") ; Only Folder, all subfolder, full path If @Error = 1 Then MsgBox(0, "", "No FilesFolders Found.") Exit EndIf While 1 For $i = 1 to $FileList[0] If DirGetSize($FileList[$i]) = 0 Then If DirRemove($FileList[$i]) Then ConsoleWrite("Dir removed: " & $FileList[$i] & @crlf) Else ConsoleWrite("Could not remove (empty?) dir: " & $FileList[$i] & @crlf) Endif Else ConsoleWrite("Not removed (contains files): " & $FileList[$i] & @crlf) Endif Next WEnd MsgBox(0, "Results", "Empty Removed") Work but...Where i need to put the exitloop? I can't stop it Edited February 3, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2012 Moderators Share Posted February 3, 2012 johnmcloud, Try using a flag like this (I have not tested it): #include <File.au3> #include <Array.au3> #include <RecFileListToArray.au3> ; External UDF $FileList = _RecFileListToArray(@WorkingDir & "Test", "*", 2, 1, 0, 2, "", "") ; Only Folder, all subfolder, full path If @error = 1 Then MsgBox(0, "", "No FilesFolders Found.") Exit EndIf Do ; Set a flag $fNoProbs = True For $i = 1 To $FileList[0] If DirGetSize($FileList[$i]) = 0 Then If DirRemove($FileList[$i]) Then ConsoleWrite("Dir removed: " & $FileList[$i] & @CRLF) Else ConsoleWrite("Could not remove (empty?) dir: " & $FileList[$i] & @CRLF) ; Clear the flag $fNoProbs = False EndIf Else ConsoleWrite("Not removed (contains files): " & $FileList[$i] & @CRLF) EndIf Next ; If the flag is set then there were no problems Until $fNoProbs MsgBox(0, "Results", "Empty Removed") Does it work for you? 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...
johnmcloud Posted February 4, 2012 Author Share Posted February 4, 2012 (edited) Yes Melba, sorry for this later answer. I need to learn this use of flag Thanks EDIT: I'm talk to early, not work. In my case i have: Func_Files() ;Delete files Func_Empty() ;Delete empty folder MsgBox(64, "OK", "Completed") The code with flag work on empty folder that was empty at start, but not with "new" empty folder Example: TopFolder/Folder_1/test.Txt TopFolder/Folder_2( empty) First function delete the .txt, the second it will delete empty folder, but... TopFolder/Folder_1/test.Txt ---> Test.txt deleted, the folder is empty but not delated TopFolder/Folder_2( empty) ---> Deleted So i have the Folder_1 and the TopFolder, together empty but not deleted I have make a sleep between the two function but the result is the same EDIT: I have verify again, it will not delete the first folder, never. Example: C:Test123asd The result is C:Test Why the "Test" folder is not processed? EDIT: Solved with another DirGetSize on the first folder. Thanks for support Edited February 4, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2012 Moderators Share Posted February 4, 2012 johnmcloud, Do you understand now how the flag works? 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