zFrank Posted August 1, 2008 Share Posted August 1, 2008 can i search for empty folders in my computer and delete them? i think ChrisL Knows how to do it because once he done something like this, if anyone is able to do it then let me know. any example would be very great. Thanks a lot in advance for the help! [font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php$Life = "Happy" If @Error Then $Life = "Risk" Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 1, 2008 Share Posted August 1, 2008 You could use FileFindFirstFile(), it sets @error to 1 if the folder is empty .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
zFrank Posted August 1, 2008 Author Share Posted August 1, 2008 can you give me a example? i am not expert in autoit just want to know how it will work. [font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php$Life = "Happy" If @Error Then $Life = "Risk" Link to comment Share on other sites More sharing options...
BrettF Posted August 1, 2008 Share Posted August 1, 2008 $folder = @ScriptDir & "\" $search = FileFindFirstFile ($folder & "*.") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If DirGetSize ($folder & $file & "\") < 1 Then MsgBox(4096, "Empty Folder:", $file) EndIf WEnd ; Close the search handle FileClose($search) Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
zFrank Posted August 1, 2008 Author Share Posted August 1, 2008 @ BrettF very good, this is what i was trying to do/know. thanks again. can we add a progress bar while searching for empty folders? how? [font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php$Life = "Happy" If @Error Then $Life = "Risk" Link to comment Share on other sites More sharing options...
BrettF Posted August 1, 2008 Share Posted August 1, 2008 I cannot and will not do everything for you. You need to try something yourself first. Go on... The helpfile is not that hard to open Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
zFrank Posted August 1, 2008 Author Share Posted August 1, 2008 (edited) ok, it is not searching in all folders it only works for the current Directory, i used $folder = "D:\" but it only works for the folders which are in only D:\ not in D:\ETC can you tell me about it? anyone else? Edited August 1, 2008 by zFrank [font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php$Life = "Happy" If @Error Then $Life = "Risk" Link to comment Share on other sites More sharing options...
LostUser Posted August 1, 2008 Share Posted August 1, 2008 You may have to do that search yourself. I haven't tried the command but after looking at the >HELP< file ... it shows that you can use FileGetAttrib on each file that is returned for FileFindNextFile. It is the "D"=Directory attribute. So you can continually look for sub directories to your hearts content it seems. Though, like I said, I haven't tried it. You will have to work out how to drill down through the directories. Good luck. Be open minded but not gullible.A hammer sees everything as a nail ... so don't be A tool ... be many tools. Link to comment Share on other sites More sharing options...
zFrank Posted August 1, 2008 Author Share Posted August 1, 2008 but at least i need a example because i tried but no success. [font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php$Life = "Happy" If @Error Then $Life = "Risk" Link to comment Share on other sites More sharing options...
ZacUSNYR Posted August 1, 2008 Share Posted August 1, 2008 but at least i need a example because i tried but no success.I made a script that does something like this.We have a program that doesn't clean itself up. I wrote the script in autoit so it goes 2 deep. There is a folder with folders underneith it. Any of the directories under that folder that are empty get deleted.If that'd work for ya I can post the code. I'm not a very good coder though heh Link to comment Share on other sites More sharing options...
JFee Posted August 1, 2008 Share Posted August 1, 2008 Create a function that calls itself. The process would be something like: Func Get list of directories from current directory Call this function on each folder inside it If the folder is empty, delete it EndFunc Can't write the code for you, but that should be a solid start. By doing it this way, it will go through each folder and check, and then delete starting with the folder that is furthest from the start (path-wise). This makes it so it will delete a folder that is full of empty folders. Regards,Josh Link to comment Share on other sites More sharing options...
JFee Posted August 1, 2008 Share Posted August 1, 2008 Alright, so consider yourself lucky. I almost never write the code for someone and post it, but I got interested by the idea and made my own little script. Very simple, yet effective. Don't even dare saying something like "This is great, but could you make it do this" or I'll be very angry. #Include <File.au3> $startDir = FileSelectFolder("Choose Directory", @HomeDrive, 2, @ScriptDir) If $startDir Then _delEmpty($startDir) Exit Func _delEmpty($dir) $folderList = _FileListToArray($dir, "*", 2) If @error <> 4 Then For $i = 1 to $folderList[0] _delEmpty($dir & "\" & $folderList[$i]) Next EndIf $fileList = _FileListToArray($dir, -1, 0) If @error = 4 Then DirRemove($dir) EndFunc Regards,Josh Link to comment Share on other sites More sharing options...
ZacUSNYR Posted August 1, 2008 Share Posted August 1, 2008 Thats great, but can you make it so it so it makes me coffee in the AM? Alright, so consider yourself lucky. I almost never write the code for someone and post it, but I got interested by the idea and made my own little script. Very simple, yet effective. Don't even dare saying something like "This is great, but could you make it do this" or I'll be very angry. #Include <File.au3> $startDir = FileSelectFolder("Choose Directory", @HomeDrive, 2, @ScriptDir) If $startDir Then _delEmpty($startDir) Exit Func _delEmpty($dir) $folderList = _FileListToArray($dir, "*", 2) If @error <> 4 Then For $i = 1 to $folderList[0] _delEmpty($dir & "\" & $folderList[$i]) Next EndIf $fileList = _FileListToArray($dir, -1, 0) If @error = 4 Then DirRemove($dir) EndFunc Link to comment Share on other sites More sharing options...
JFee Posted August 1, 2008 Share Posted August 1, 2008 How's this? #Include <File.au3> #Include <Coffee.au3> If @HOUR >= 5 And @HOUR <= 10 Then _GetCoffee() If @error = 1 Then MsgBox(1, "No beans", "Out of beans!") EndIf $startDir = FileSelectFolder("Choose Directory", @HomeDrive, 2, @ScriptDir) If $startDir Then _delEmpty($startDir) Exit Func _delEmpty($dir) $folderList = _FileListToArray($dir, "*", 2) If @error <> 4 Then For $i = 1 to $folderList[0] _delEmpty($dir & "\" & $folderList[$i]) Next EndIf $fileList = _FileListToArray($dir, -1, 0) If @error = 4 Then DirRemove($dir) EndFunc Regards,Josh 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