Page 1 of 1

Delete empty folders

Posted: 29 Dec 2009 16:37
by vdongen
Hi.

Possible to search for and delete empty folders?

Bart

Re: Delete empty folders

Posted: 29 Dec 2009 17:13
by zer0
Yes. Go to 'Edit' -> 'Find Files...'. Set the location where you want to search, tick 'Include subfolders'. Tick only the 'Size' filter on the right, below the search buttons. On the 'Size' tab, put 0 in the 'At the most' text box and tick 'Search for folders as well'. Do the search and list of empty folders will appear.

P.S. Empty files will be mentioned too, but it's easy to filter them out :)

Re: Delete empty folders

Posted: 29 Dec 2009 18:24
by serendipity
I made a little script sometime back to do exactly this. Updated a bit now:

Code: Select all

//get folder sizes
   #487;
//select first item
   sel 1;
//empty clipboard
   copytext "";
//get position
   $pos=getinfo ("FocusedPos");
//get item count
   $items=getinfo ("Countitems");

//Loop until end  
   WHILE ($pos<=$items)
   {
//get type
   $type=property("Type","<curitem>");
//get size
   $size=report("{Size}",1);

//Has to be a folder and has to be empty
      IF ($type == "File folder" && $size == "-") 
      { 
//copy current item     
       copytext <curitem>|,a;
       incr $pos;
       sel $pos;
      }
      ELSE 
      {
      incr $pos;
      sel $pos;
      }
   }
//set clipboard to variable
   $clipboard=<clipboard>;
//remove trailing |
   $clipboard=substr ($clipboard, 0,-1);
//replace | with <crlf> for displaying text
   replace $clipboard, $clipboard, "|","<crlf>";
//display items to be deleted
   text $clipboard,,,"Items to be deleted";
//replace <crlf> with | for deletion
   replace $clipboard, $clipboard, "<crlf>","|";
//delete empty folders, move to recycle bin and prompt before delete
   delete 1,1, "$clipboard";
//
   status "Empty folders deleted";    

Re: Delete empty folders

Posted: 05 Jan 2010 13:37
by vdongen
Thanks guys.

Bart

Re: Delete empty folders

Posted: 16 Oct 2010 02:04
by serendipity
Skyfrontier reported that this script no longer works, so here is the updated version.

Code: Select all

//Delete Empty folders
  #487;//Get Folder sizes 
  selfilter "Empty", d, "size";// Select empty folders
  focus;//Without this only one focused item is returned
  $items= get("SelectedItemsNames", "|+");//Get names of Selected items
  IF($items==""){
  status "No empty folders found.",,alert;
  end(1==1);
  }
  $tobedeleted= inputselect("To be deleted folders" ,+.$items, "|",2);//Shows list of folders (pre-checked) that will be deleted. You have the option to uncheck folders 
  selfilter "$tobedeleted";//Selects folders in list based on user's check/uncheck input
  delete 1, 1, :list;//Deletes folders to recycle bin, asks for confirmation. Remove both 1s to skip recycle and confirmation
I am amazed how much smaller this has become. Thanks to new commands.

Re: Delete empty folders

Posted: 16 Oct 2010 02:49
by SkyFrontier
Hmmmmm... Testing against test folders

Code: Select all

C:\test\New Folder-01\New Folder
C:\test\New Folder-01\New Folder-01
C:\test\New Folder-01\New Folder-02
C:\test\New Folder-01\New Folder-03
C:\test\New Folder-01\New Folder-04
with and without contents (sometimes a test file "New Textfile.txt", empty/zero size, sometimes with 1 char as content) I got random results like: deleting everything, deleting nothing, deleting 1 folder with/without test file. It's so erratic that I can't define a pattern and post a note about it.
-can someone please confirm?
>I made an update at the Library under the tag "Delete Empty Folders" and left a note regarding the problem, anyway.
Thank you!

EDIT: Tested on v.9.60.0009 (current beta).

Re: Delete empty folders

Posted: 16 Oct 2010 03:03
by SkyFrontier
Worst problem so far: it tells correctly which folder(s) will delete but ends deleting everything (=all folders, with and without content!), in fact.
-erratically, too.

EDIT: Even worse: the code do makes sense... :roll:

Re: Delete empty folders

Posted: 16 Oct 2010 03:22
by serendipity
Sorry, there is a small bug. Fixing it. will post back soon.
Edit: here it is again:

Code: Select all

//Delete Empty folders
  #487;//Get Folder sizes 
  selfilter "Empty", d, "size";// Select empty folders
  focus;//Without this only one focused item is returned
  $items= get("SelectedItemsNames", "|+");//Get names of Selected items
  IF($items==""){
  status "No empty folders found.",,alert;
  end(1==1);
  }
  $tobedeleted= inputselect("To be deleted folders" ,+.$items, "|",2);//Shows list of folders (pre-checked) that will be deleted. You have the option to uncheck folders 
  $char=chr(34);
  $tobedeleted=replace ($tobedeleted, "|","$char|$char");
  $tobedeleted=$char.$tobedeleted.$char;

  selfilter "$tobedeleted";//Selects folders in list based on user's check/uncheck input
  delete 1, 1, :list;//Deletes folders to recycle bin, asks for confirmation. Remove both 1s to skip recycle and confirmation

Re: Delete empty folders

Posted: 16 Oct 2010 09:04
by SkyFrontier
Tested, working, Library updated.
Many thanks!

Note: it must be used without any folder being selected, otherwise script will consider only selected/items displaying [empty] as per folder size.

Re: Delete empty folders

Posted: 16 Oct 2010 09:18
by SkyFrontier
Let's suppose I want to check all subfolders of a folder. Am I doing any dumbness using the script like this? Any potential damages involved...?
(using the "quote" mode to highlight change; consider adding blank spaces to get the script fully functional!)
Decent version:

Code: Select all

//Delete Empty Folders
   #263;//all items on a branch
   #487;//Get Folder sizes
   selfilter "Empty", d, "size";// Select empty folders
   focus;//Without this only one focused item is returned
   $items= get("SelectedItemsNames", "|+");//Get names of Selected items
   IF($items==""){
   status "No empty folders found.",,alert;
   end(1==1);
   }
   $tobedeleted= inputselect("To be deleted folders" ,+.$items, "|",2);//Shows list of folders (pre-checked) that will be deleted. You have the option to uncheck folders
   $char=chr(34);
   $tobedeleted=replace ($tobedeleted, "|","$char|$char");
   $tobedeleted=$char.$tobedeleted.$char;

   selfilter "$tobedeleted";//Selects folders in list based on user's check/uncheck input
   delete 1, 1, :list;//Deletes folders to recycle bin, asks for confirmation. Remove both 1s to skip recycle and confirmation
//Delete Empty folders
#263;//all items on a branch
#487;//Get Folder sizes
selfilter "Empty", d, "size";// Select empty folders
focus;//Without this only one focused item is returned
$items= get("SelectedItemsNames", "|+");//Get names of Selected items
IF($items==""){
status "No empty folders found.",,alert;
end(1==1);
}
$tobedeleted= inputselect("To be deleted folders" ,+.$items, "|",2);//Shows list of folders (pre-checked) that will be deleted. You have the option to uncheck folders
$char=chr(34);
$tobedeleted=replace ($tobedeleted, "|","$char|$char");
$tobedeleted=$char.$tobedeleted.$char;

selfilter "$tobedeleted";//Selects folders in list based on user's check/uncheck input
delete 1, 1, :list;//Deletes folders to recycle bin, asks for confirmation. Remove both 1s to skip recycle and confirmation

Re: Delete empty folders

Posted: 09 Nov 2018 07:09
by Nasri
zer0 wrote: 29 Dec 2009 17:13 Yes. Go to 'Edit' -> 'Find Files...'. Set the location where you want to search, tick 'Include subfolders'. Tick only the 'Size' filter on the right, below the search buttons. On the 'Size' tab, put 0 in the 'At the most' text box and tick 'Search for folders as well'. Do the search and list of empty folders will appear.

P.S. Empty files will be mentioned too, but it's easy to filter them out :)
Thank you, this works for me! :)

Re: Delete empty folders

Posted: 09 Nov 2018 14:20
by RalphM
Surely a long awaited thanks - almost 9 years in the making. :whistle:

Re: Delete empty folders

Posted: 22 Jul 2021 18:54
by Nasri
zer0 wrote: 29 Dec 2009 17:13 Yes. Go to 'Edit' -> 'Find Files...'. Set the location where you want to search, tick 'Include subfolders'. Tick only the 'Size' filter on the right, below the search buttons. On the 'Size' tab, put 0 in the 'At the most' text box and tick 'Search for folders as well'. Do the search and list of empty folders will appear.
P.S. Empty files will be mentioned too, but it's easy to filter them out :)
Still a classic, albeit manual, it just works for me on v21.10 :D