That's funny, I also made my own version of this lately. daorc, it's important that you check the errorlevel after the fileselectfolder command. If the user clicks the Cancel button in the fileselectfolder window, your WhichFolder variable remains empty which could potentially have some nasty side effects! Also, deleting all folders less than 100 kb seeems quite risky as small files can be very important and a file of 100 kb can hold a whole lot of text.
I'm sure Skan's code is very good, but as often is the case I don't understand it.
Skan: What do you mean by "inside-out"? Does it mean that you start deleting empty folders at the "deepest" level and then work your way back up the folder tree? I think I had problems with my script because if a folder contained an empty subfolder, only the subfolder would be deleted. If I would run the script again it would delete the "now-empty" folder as well.
Here's my version:
Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
FileSelectFolder, TopFolder, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 3, Select topmost folder. All empty subfolders will be deleted.
if not(InStr(FileExist(TopFolder), "D"))
{
soundbeep
msgbox, Aborting...
exitapp
}
DelFolderCount := 0
DelErrorCount := 0
Loop, %TopFolder%\*.*, 2, 1
{
counter := 0
Loop, %A_LoopFileFullPath%\*.*, 0, 1
{
counter++
}
if counter = 0
{
FileRemoveDir, %A_LoopFileFullPath%, 1
if errorlevel <> 0
DelErrorCount++
else
DelFolderCount++
Fileappend, %ErrorLevel% errors when deleting %A_LoopFileFullPath%`n, DeleteLog.txt
}
}
msgbox, Deleted %DelFolderCount% empty folders. (%DelErrorCount% errors.)