snowman533 Posted April 16, 2009 Share Posted April 16, 2009 $ddnumber=0 $dsize=DirGetSize(@scriptdir & "\*") if $dsize = 0 Then While $dsize = 0 DirRemove($dsize) $ddnumber += 1 WEnd Else Exit EndIf If $ddnumber=0 Then msgbox(0,"No empty directories", "No empty directories found") Else MsgBox(0,"Results", $ddnumber & " empty directories removed") EndIf basically this searches for and removes all empty directories, at the moment i am using @scriptdir to test, i cant get the dang thing to run what am i missing? thanks in advance this will be added to my utilities collection Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
KaFu Posted April 16, 2009 Share Posted April 16, 2009 (edited) Willcards do not work with DirGetSize, create a sub-dir 'test' in script dir. $dsize=DirGetSize(@scriptdir & "\*") ConsoleWrite($dsize & @crlf) $dsize=DirGetSize(@scriptdir & "\test") ConsoleWrite($dsize & @crlf) To catch all dirs you'll have to parse through a filelist, maybe with a loop based on _FileListToArray() and a check like StringInStr(FileGetAttrib($filename),"D") to validate found file is a dir. Edit: Your while loop hangs the script . Edited April 16, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
snowman533 Posted April 16, 2009 Author Share Posted April 16, 2009 (edited) hmm tried creating a folder called test and coding that in the script just sits there taking up the CPU what am i missing from my script? or what is wrong with it? christ, arrays are a pain to learn but theyl save me one day, i think Edited April 16, 2009 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
KaFu Posted April 16, 2009 Share Posted April 16, 2009 #Include <File.au3> #Include <Array.au3> $ddnumber=0 $FileList=_FileListToArray(@ScriptDir) 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) $ddnumber +=1 Else ConsoleWrite("Could not remove (empty?) dir: " & $FileList[$i] & @crlf) endif Else ConsoleWrite("Dir not removed (contains files): " & $FileList[$i] & @crlf) endif EndIf Next If $ddnumber=0 Then msgbox(0,"No empty directories", "No empty directories found") Else MsgBox(0,"Results", $ddnumber & " empty directories removed") EndIf OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
snowman533 Posted April 16, 2009 Author Share Posted April 16, 2009 (edited) thanks, now to learn about those arrays any ways to add all subdirectories and all subdirectories beyond that? Edited April 16, 2009 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
snowman533 Posted April 16, 2009 Author Share Posted April 16, 2009 (edited) cool, thanks again one last thing thats been bothering me, i cannot find the answer for this how can i set up a control that will let you browse for a directory to set as the base directory? and also, after a test on that script, it only affects the scripts directory and not any of the subdirectories or any of their subs or any of their subs and so on Edited April 16, 2009 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
KaFu Posted April 16, 2009 Share Posted April 16, 2009 (edited) FileSelectFolder() and search forum for recursive filesearch functions to replace _FileListToArray() ... Edited April 16, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
snowman533 Posted April 16, 2009 Author Share Posted April 16, 2009 thanks, i have made a post on one of the function topics, hopefully someone can help me furtherthanks again KaFu you have my credithttp://www.autoitscript.com/forum/index.ph...mp;#entry670500 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
KaFu Posted April 16, 2009 Share Posted April 16, 2009 U looked at an example not fitting your needs, this one fits better:#1 - Array based from #442099expandcollapse popup#include <array.au3> $ddnumber = 0 $var = FileSelectFolder("Delete Empty directories from:", "", 7) If @error Then Exit $FileList = RecursiveFileSearch($var, "", "", 2, True) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf ;_ArrayDisplay($FileList) For $i = 1 To $FileList[0] If StringInStr(FileGetAttrib($FileList[$i]), "D") Then; If parent (empty) dir has already been deleted, FileGetAttrib returns Blank and further analysis is skiped. If DirGetSize($FileList[$i]) = 0 Then If DirRemove($FileList[$i]) Then ConsoleWrite("Dir removed: " & $FileList[$i] & @CRLF) $ddnumber += 1 Else ConsoleWrite("Could not remove (empty?) dir: " & $FileList[$i] & @CRLF) EndIf Else ConsoleWrite("Dir not removed (contains files): " & $FileList[$i] & @CRLF) EndIf EndIf Next If $ddnumber = 0 Then MsgBox(0, "No empty directories", "No empty directories found") Else MsgBox(0, "Results", $ddnumber & " empty directories removed") EndIf #cs ---------------------------------------------------------------------------- #1 - Array based from http://www.autoitscript.com/forum/index.php?showtopic=58558&view=findpost&p=442099 AutoIt Version: 3.2.10.0 Author: WeaponX Updated: 2/21/08 Script Function: Recursive file search 2/21/08 - Added pattern for folder matching, flag for return type 1/24/08 - Recursion is now optional Parameters: RFSstartdir: Path to starting folder RFSFilepattern: RegEx pattern to match "\.(mp3)" - Find all mp3 files - case sensitive (by default) "(?i)\.(mp3)" - Find all mp3 files - case insensitive "(?-i)\.(mp3|txt)" - Find all mp3 and txt files - case sensitive RFSFolderpattern: "(Music|Movies)" - Only match folders named Music or Movies - case sensitive (by default) "(?i)(Music|Movies)" - Only match folders named Music or Movies - case insensitive "(?!(Music|Movies)\b)\b.+" - Match folders NOT named Music or Movies - case sensitive (by default) RFSFlag: Specifies what is returned in the array 0 - Files and folders 1 - Files only 2 - Folders only RFSrecurse: TRUE = Recursive, FALSE = Non-recursive RFSdepth: Internal use only #ce ---------------------------------------------------------------------------- Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = True, $RFSdepth = 0) ;Ensure starting folder has a trailing slash If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\" If $RFSdepth = 0 Then ;Get count of all files in subfolders for initial array definition $RFSfilecount = DirGetSize($RFSstartDir, 1) ;File count + folder count (will be resized when the function returns) Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1] EndIf $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*") If @error Then Return ;Search through all files and folders in directory While 1 $RFSnext = FileFindNextFile($RFSsearch) If @error Then ExitLoop ;If folder and recurse flag is set and regex matches If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then If $RFSrecurse And StringRegExp($RFSnext, $RFSFolderpattern, 0) Then RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1) If $RFSFlag <> 1 Then ;Append folder name to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext $RFSarray[0] += 1 EndIf EndIf ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) And $RFSFlag <> 2 Then ;Append file name to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext $RFSarray[0] += 1 EndIf WEnd FileClose($RFSsearch) If $RFSdepth = 0 Then ReDim $RFSarray[$RFSarray[0] + 1] Return $RFSarray EndIf EndFunc ;==>RecursiveFileSearch robertocm 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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