Delete Empty Folders

Discuss RoboTask here
Post Reply
dbortunk
Posts: 27
Joined: Mon Jun 08, 2009 10:38 am

Delete Empty Folders

Post by dbortunk »

Is there a way to delete empty folders with Robotask? Meaning in a directory tree only delete the folders that are empty
Last edited by dbortunk on Mon Jun 08, 2009 6:00 pm, edited 1 time in total.
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Delete Empty Folders

Post 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
Last edited by Oleg on Tue Jun 09, 2009 12:44 pm, edited 1 time in total.
dbortunk
Posts: 27
Joined: Mon Jun 08, 2009 10:38 am

Delete Empty Folders

Post 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
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Delete Empty Folders

Post 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
dbortunk
Posts: 27
Joined: Mon Jun 08, 2009 10:38 am

Delete Empty Folders

Post 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.
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Delete Empty Folders

Post 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
Post Reply