Page 1 of 4

Delete empty folders (one-click function)

Posted: 2022-05-19, 19:10 UTC
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

Re: Delete empty folders (one-click function)

Posted: 2022-05-19, 19:27 UTC
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.

Re: Delete empty folders (one-click function)

Posted: 2022-05-19, 21:10 UTC
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?

Re: Delete empty folders (one-click function)

Posted: 2022-05-20, 14:17 UTC
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.

Re: Delete empty folders (one-click function)

Posted: 2022-05-20, 19:33 UTC
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.

Re: Delete empty folders (one-click function)

Posted: 2022-05-20, 20:22 UTC
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. )

Re: Delete empty folders (one-click function)

Posted: 2022-05-21, 08:22 UTC
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.

Re: Delete empty folders (one-click function)

Posted: 2022-05-21, 12:20 UTC
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.

Re: Delete empty folders (one-click function)

Posted: 2022-05-21, 16:45 UTC
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

Re: Delete empty folders (one-click function)

Posted: 2022-05-21, 17:19 UTC
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.

Re: Delete empty folders (one-click function)

Posted: 2022-05-21, 17:24 UTC
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

Re: Delete empty folders (one-click function)

Posted: 2022-05-22, 15:30 UTC
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?

Re: Delete empty folders (one-click function)

Posted: 2022-05-22, 15:56 UTC
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.

Re: Delete empty folders (one-click function)

Posted: 2022-05-22, 16:01 UTC
by oko
to Flasher
Where has VBS code to be pasted?

Re: Delete empty folders (one-click function)

Posted: 2022-05-22, 16:04 UTC
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