Page 1 of 1

Delete Empty Folders

Posted: Mon Jun 08, 2009 1:59 pm
by dbortunk
Is there a way to delete empty folders with Robotask? Meaning in a directory tree only delete the folders that are empty

Delete Empty Folders

Posted: Tue Jun 09, 2009 8:44 am
by Oleg
Look at the "Remove folder" action.
Also you may check folder size before deleting, like this:

if {FolderSize(c:\myfolder\subfolder)}=0 then
   Remove folder c:\myfolder\subfolder
end if

Delete Empty Folders

Posted: Tue Jun 09, 2009 12:16 pm
by dbortunk
Yes but i am asking if it can delete all empty folders in a directory tree. There may be 5 there may be 500. The code you pasted will delete a specific folder

Delete Empty Folders

Posted: Tue Jun 09, 2009 11:02 pm
by Oleg
Use this algorithm in the "File loop" action.
Like this:

File loop //by folders
   if {FolderSize({CurrentFolder})}=0 then
      Remove folder {CurrentFolder}
   end if
end loop

Delete Empty Folders

Posted: Wed Jun 10, 2009 8:55 am
by dbortunk
It stops when it finds a folder with a file in it. I would assume that it would skip that folder and move on to the next folder because of the loop but that is not happening.

Delete Empty Folders

Posted: Wed Jun 10, 2009 9:42 am
by Oleg
There is {FilesCount()} variable. It counts the amount of files in the folder and subfolders.

File loop //by folders
   if {FilesCount({CurrentFolder})}=0 then
      Remove folder {CurrentFolder}
   end if
end loop