Delete empty folders
Posted: 29 Dec 2009 16:37
Hi.
Possible to search for and delete empty folders?
Bart
Possible to search for and delete empty folders?
Bart
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
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";
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
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
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
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
Thank you, this works for me!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.10zer0 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