Only read further if you do not want to try to write the script yourself. Here it is in 17 lines:
Code:
DelEmpty(dir)
{
FileGetAttrib Attrib, %dir%
FileGetTime ModTime, %dir%, M
FileGetTime CreateTime,%dir%, C
Loop %dir%\*.*, 2
DelEmpty(A_LoopFileFullPath)
FileRemoveDir %dir%
IfEqual ErrorLevel,1, Return
MsgBox 4,,Remove directory %dir%?`nCreated: %CreateTime%`nModified: %ModTime%
IfMsgBox Yes
Return
FileCreateDir %dir%
FileSetAttrib +%Attrib%, %dir%
FileSetTime %CreateTime%,%dir%, C
FileSetTime %ModTime%, %dir%, M
}
Here is a version in 19 lines, which also sets the global variable "kept" to the number of empty directories not deleted.
Code:
DelEmpty(dir)
{
Global kept
FileGetAttrib Attrib, %dir%
FileGetTime ModTime, %dir%, M
FileGetTime CreateTime,%dir%, C
Loop %dir%\*.*, 2
DelEmpty(A_LoopFileFullPath)
FileRemoveDir %dir%
IfEqual ErrorLevel,1, Return
MsgBox 4,,Remove directory %dir%?`nCreated: %CreateTime%`nModified: %ModTime%
IfMsgBox Yes
Return
kept += 1
FileCreateDir %dir%
FileSetAttrib +%Attrib%, %dir%
FileSetTime %CreateTime%,%dir%, C
FileSetTime %ModTime%, %dir%, M
}
If you also count the total number of subdirectories encountered (global total) and the number of empty directories, which were deleted (global deleted), the number of lines in the function grows to 22, but 2 of them has no code, only the delimiting braces.
Code:
DelEmpty(dir)
{
Global total, deleted, kept
total += 1
FileGetAttrib Attrib, %dir%
FileGetTime ModTime, %dir%, M
FileGetTime CreateTime,%dir%, C
Loop %dir%\*.*, 2
DelEmpty(A_LoopFileFullPath)
FileRemoveDir %dir%
IfEqual ErrorLevel,1, Return
deleted += 1
MsgBox 4,,Remove directory %dir%?`nCreated: %CreateTime%`nModified: %ModTime%
IfMsgBox Yes
Return
kept += 1
deleted -= 1
FileCreateDir %dir%
FileSetAttrib +%Attrib%, %dir%
FileSetTime %CreateTime%,%dir%, C
FileSetTime %ModTime%, %dir%, M
}