Delete empty folders (one-click function)

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Delete empty folders (one-click function)

Post by *oko »

It would be usefull to have one-click function for deleting empty folders. User would not have to go through many steps to do that job. The function would function like that:
For each folder - if count of files=0 and folders=0 then delete else ignore (skip) - next folder. Repeat the For each folder... till no empty folder is found.
There could be option to delete or ignore folders with description.

Related post: https://www.ghisler.ch/board/viewtopic.php?t=76689
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6450
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Delete empty folders (one-click function)

Post by *Horst.Epp »

Thats already easy done using an Everything search in TC like the following:
ev:D:\ folder: childcount:0
Finds all empty folders on drive D: which don't contain any file or folder.
Other options of Everything are also possible.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

to Horst.Epp:
Is it one-click function? My request is one-click.
Do I have to write path or it is given from active window? My request is not to write but be in folder and click to delete empty folders in it.
What is result? Will all empty folders be deleted, or will it only search empty folders? You write "finds", but my request is "delete".
Do I have to repeat it if there are descript.ion files? My request is one-click, no multiply.

I want full automated process without clicking, writing, selecting, repeating etc.
I use method described here: https://www.ghisler.ch/board/viewtopic.php?t=76689
Is Everything better than my method?
Last edited by oko on 2022-05-20, 19:37 UTC, edited 1 time in total.
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: Delete empty folders (one-click function)

Post by *Fla$her »

2oko
These kinds of tasks are done by scripts. You can already find a bunch of options on the web to delete empty folders.
Overquoting is evil! πŸ‘Ž
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

to Flasher
Yes, done by sripts, options on the web, external solutions and combinations... but not simple and trusted one-click function built in TC. It is TC suggestion topic, so I automatically suppose to have this function built in TC, do not consider external solutions. It is feature request for TC.
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: Delete empty folders (one-click function)

Post by *Fla$her »

2oko
"These kinds of" means that you can forget about the function in TC. There won't be this, 100%, as well as heaps of even less specific things. Therefore, only a script with one trusted click. )
Overquoting is evil! πŸ‘Ž
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6450
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Delete empty folders (one-click function)

Post by *Horst.Epp »

oko wrote: ↑2022-05-19, 21:10 UTC to Horst.Epp:
Is it one-click function? My request is one-click.
Do I have to write path or it is given from active window? My request is not to write but be in folder and click to delete empty folders in it.
What is result? Will all empty folders be deleted, or will it only search empty folders? You write "finds", but my request is "delete".
Do I have to repeat it if there are descript.ion files? My request is one-click, no multiply.

I want full automated process without clicking, writing, selecting, repeating etc.
I use method described here: https://www.ghisler.ch/board/viewtopic.php?t=76689
Is Everything better than my method?
You don't have to enter paths if you use ed: instead of ev:
as this uses the current TC source path.
Its not a one click, you have to feed the results to the list box, select all and hit delete.
I don't have the need to delete empty dirs often.
Its nothing urgent and therefore I don't need a one click action.
But if that is importand you have to script it.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Delete empty folders (one-click function)

Post by *petermad »

2oko
I can make a button for you that automates this method - you only have to click one time to confirm that you want to delete - is that of interest?

Is Everything better than my method?
No, it is worse - because it only finds the outermost directories - so if you have c:\xx\yy\zz and xx and yy are enpty except for the next subdir, only zz gets deleted, you would have to run the command two times more to delete yy and zz.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Vochomurka
Power Member
Power Member
Posts: 814
Joined: 2005-09-14, 22:19 UTC
Location: Russia
Contact:

Re: Delete empty folders (one-click function)

Post by *Vochomurka »

I use Xxcopy tool for this purpose. I created batch file with one line

Code: Select all

xxcopy.exe %1 /rmdir /x*.* /yy
It's exactly one-click button :D
Single user license #329241
PowerPro scripts for Total Commander
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Delete empty folders (one-click function)

Post by *petermad »

A button solution, using the dirsizecalc plugin could be:

Add this to the [Searches] section of your wincmd.ini file:

Code: Select all

Empty folders_SearchFor=
Empty folders_SearchIn=
Empty folders_SearchText=
Empty folders_SearchFlags=0|012002010021|||||||||0000|||
Empty folders_plugin="dirsizecalc.Contains Files" = No
And add this to your usercmd.ini file:

Code: Select all

[em_findEmptyFolders]
cmd=LOADSEARCH ==Empty folders
And make this button:

Code: Select all

TOTALCMD#BAR#DATA
cm_SrcByExt 2,em_findEmptyFolders,cm_SwitchDirSort 2,cm_SrcByExt 2,cm_SelectAllFolders,cm_Delete,cm_GoToParent,cm_SrcByName

wciconex.dll,64
Delete empty folders (DirSizecalc plugin)


-1
To make the button:
1. Mark the text in the box here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".
______________________________

Altenative solution using 'Everything':

Add this to the [Searches] section of your wincmd.ini file:

Code: Select all

Empty folders ev_SearchFor=ed: folder: size:0
Empty folders ev_SearchIn=
Empty folders ev_SearchText=
Empty folders ev_SearchFlags=0|012002010021|||||||||0000|||
And add this to your usercmd.ini file:

Code: Select all

[em_findEmptyFoldersEV]
cmd=LOADSEARCH ==Empty folders ev
And make this button:

Code: Select all

TOTALCMD#BAR#DATA
cm_SrcByExt 2,em_findEmptyFoldersEV,cm_SwitchDirSort 2,cm_SrcByExt 2,cm_SelectAllFolders,cm_Delete,cm_GoToParent,cm_SrcByName

wciconex.dll,64
Delete empty folders ('Everything')


-1
To make the button:
1. Mark the text in the box here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".

The buttons will not always work properly If there are . (dots) in the folder name and the parameter SortDirExt=1 is set in wincmd.ini. SortDirExt=1 is NOT default for TC and can ONLY be set by adding it manually to wincmd.ini - so most users will not have this setting.

If you do not want to end up with sorting by Name, you can change the cm_SrcByName to the sort order you want.
If you do not want to end up with sorting folders like files you can ADD cm_SwitchDirSort 1 to the end of the command line.

The sorting commands in the multi commad line are necessary to make TC delete the folders deepest in the paths first.
Last edited by petermad on 2022-05-25, 00:21 UTC, edited 2 times in total.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: Delete empty folders (one-click function)

Post by *Fla$her »

Code: Select all

'β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” VBS β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
' Recursive deletion of empty subdirectories
' Parameter: "<folder path>" (for example, "%P")
'β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
Option Explicit: Dim Dir, FSO, Col, D
Dir = "\\?\" & WSH.Arguments(0)
Const Title = " Deleting empty subfolders     "
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Col = CreateObject("System.Collections.ArrayList")
If Not FSO.FolderExists(Dir) Then _
MsgBox "Set the path to the existing directory!", 262192, Title: WSH.Quit
Recursion FSO.GetFolder(Dir)
Col.Sort : Col.Reverse
For Each D in Col
   Set D = FSO.GetFolder(D)
   If D.SubFolders.Count = 0 And D.Files.Count = 0 Then D.Delete 1
Next
Set FSO = Nothing : Set Col = Nothing
CreateObject("WScript.Shell").Popup "  Done!", 1.7, Title, 4160

Sub Recursion(oDir)
  For Each D in oDir.SubFolders
    If D.SubFolders.Count Then Col.Add D.Path :_
    Recursion D Else If D.Files.Count = 0 Then D.Delete 1
  Next
End Sub
Last edited by Fla$her on 2022-05-22, 17:16 UTC, edited 1 time in total.
Overquoting is evil! πŸ‘Ž
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

Vochomurka wrote: ↑2022-05-21, 16:45 UTC I use Xxcopy tool for this purpose. I created batch file with one line

Code: Select all

xxcopy.exe %1 /rmdir /x*.* /yy
It's exactly one-click button :D
Is it fun? Where are criteria?
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

to petermad
your button solution seems interesting. I will try. I have question for now.
1. It seems to do only one deletion. Or does it repeat till no empty folders found?
2. Could it be done without dirsizecalc or any other plugin? I mean only TC without plugins would be used for all steps.
Last edited by oko on 2022-05-22, 16:04 UTC, edited 1 time in total.
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

to Flasher
Where has VBS code to be pasted?
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6450
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Delete empty folders (one-click function)

Post by *Horst.Epp »

This searches with TC have the disadvantage that the full results for many dirs can't be checked before deletion.
Following some other thread to this topic I have found the tool RED2 very usefull.
It contains a lot of settings to make a smoth and safe deletion.
It also allows to exclude path and file names.
I use the current beta.
https://www.jonasjohn.de/red.htm
Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
Post Reply