Delete empty folders
Delete empty folders
Hi.
Possible to search for and delete empty folders?
Bart
Possible to search for and delete empty folders?
Bart
Re: Delete empty folders
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
P.S. Empty files will be mentioned too, but it's easy to filter them out
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build
Windows 7/10
Always using the latest stable two-decimal build
-
- Posts: 3358
- Joined: 07 May 2007 18:14
- Location: NJ/NY
Re: Delete empty folders
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
Thanks guys.
Bart
Bart
-
- Posts: 3358
- Joined: 07 May 2007 18:14
- Location: NJ/NY
Re: Delete empty folders
Skyfrontier reported that this script no longer works, so here is the updated version.
I am amazed how much smaller this has become. Thanks to new commands.
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
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Delete empty folders
Hmmmmm... Testing against test folders
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).
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
-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).
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Delete empty folders
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...
-erratically, too.
EDIT: Even worse: the code do makes sense...
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
- Posts: 3358
- Joined: 07 May 2007 18:14
- Location: NJ/NY
Re: Delete empty folders
Sorry, there is a small bug. Fixing it. will post back soon.
Edit: here it is again:
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
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Delete empty folders
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.
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.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Delete empty folders
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:
(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
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Re: Delete empty folders
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
Re: Delete empty folders
Surely a long awaited thanks - almost 9 years in the making.
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
Re: Delete empty folders
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