Delete empty folders (one-click function)

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

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 »

oko wrote: ↑2022-05-22, 15:30 UTCWhere are criteria?
/X<xspec> Adds an exclusion specifier (xspec) (see below for exclusion).

Code: Select all

TOTALCMD#BAR#DATA
%$System%\xxcopy.exe
"%P" /rmdir /x* /yy
xxcopy.exe,2
Delete empty subfolders

1
oko wrote: ↑2022-05-22, 16:01 UTCWhere has VBS code to be pasted?
Save with .vbs extension, drag from the filelist to the toolbar and set the parameter in the button.
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 »

Horst.Epp wrote: ↑2022-05-22, 16:04 UTC This searches with TC have the disadvantage that the full results for many dirs can't be checked before deletion.
With TC searches list of empty folders is available before deletion (after "Feed to list" is clicked). You can select all or some. However, structure is missing (it is only list). For example for me the list is sufficient and I do not have to jump out of TC. Of course for more requirements specific software can be better.
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-22, 16:29 UTC
Horst.Epp wrote: ↑2022-05-22, 16:04 UTC This searches with TC have the disadvantage that the full results for many dirs can't be checked before deletion.
With TC searches list of empty folders is available before deletion (after "Feed to list" is clicked). You can select all or some.
Thats ony true if none of the one click solutions above is used.
In this versions you only see a short list and no chance to check the full list of found dirs.
Of course if I use only the searches I can fully check the results.
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
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
Fixed the script for deleting empty matryoshkas.
Overquoting is evil! πŸ‘Ž
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 »

oko wrote: ↑2022-05-22, 15:56 UTC 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.
1. It should delete all empty folders, because it starts deleting the ones that are last in each path found.

2. No, you need either DirSizeCalc or 'Everything'
Last edited by petermad on 2022-05-23, 12:27 UTC, edited 1 time 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
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 »

oko wrote: ↑2022-05-22, 15:30 UTC
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?
Just try it :D
I use it for several years
Single user license #329241
PowerPro scripts for Total Commander
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

petermad wrote: ↑2022-05-23, 04:08 UTC
oko wrote: ↑2022-05-22, 15:56 UTC 1. It seems to do only one deletion. Or does it repeat till no empty folders found?
1. It should delete all empty folders, because it starts deleting the ones that are last in each path found.
As I have tested it works good, but as I mentioned here https://www.ghisler.ch/board/viewtopic.php?t=76689, if there are some empty folders with description, some empty folders remain undeleted. Multiple deletions are needed.
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

petermad wrote: ↑2022-05-21, 17:19 UTC 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 pluin)


-1
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.
1) There has not been wciconex.dll but wcmicons.dll or wcmicon2.dll in my installation folder.

2) As I have tested it works also without sorting (if sorting should be problem). But in that case one more click is needed because message "folder is not empty" appears during running. It is ok to click All. Command without sorting:

Code: Select all

em_findEmptyFolders,cm_SelectAllFolders,cm_Delete,cm_GoToParent
Sorting brings more convenience. Maybe unsorting could be quicker if huge count of folders are deleted.

3) I must be careful if no empty folders are found as it is going to delete whole folder. Fortunately gives question if I want. I click NO. Then it goes to folder one level up. It is also a bit inconvenience.
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
I don't understand why you spend so much energy discussing what doesn't suit you, but ignore the provided one-button solutions that do what you need? :?
Overquoting is evil! πŸ‘Ž
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 »

1) There has not been wciconex.dll but wcmicons.dll or wcmicon2.dll in my installation folder.
Sorry about the wciconex.dll - you can find it here: https://www.ghisler.ch/board/viewtopic.php?t=13418

2) As I have tested it works also without sorting (if sorting should be problem). But in that case one more click is needed because message "folder is not empty" appears during running. It is ok to click All. Command without sorting:
It could be much more than just one time you would have to click "All", depending on the distribution of the folders

if there are some empty folders with description, some empty folders remain undeleted
Of course - technically the folders are not empty then.

3) I must be careful if no empty folders are found as it is going to delete whole folder. Fortunately gives question if I want. I click NO. Then it goes to folder one level up. It is also a bit inconvenience.
Sure - but there will be nothing to feed to listbox, so TC will stop in the Search dialog first, so you are warned before the next dialog that ask if you want to delete selected folders pops up.
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
oko
Senior Member
Senior Member
Posts: 200
Joined: 2007-05-03, 16:22 UTC

Re: Delete empty folders (one-click function)

Post by *oko »

Fla$her wrote: ↑2022-05-24, 17:34 UTC 2oko
I don't understand why you spend so much energy discussing what doesn't suit you, but ignore the provided one-button solutions that do what you need? :?
I can explain. I have requested TC build-in function. Instead I got more alternative solutions from more advicers (much thanks), which I must study, understand and test and it spends time and then I inform you or eventually other readers what criteria are not met or what it does or not. When I have results I share with all. And also for advisers then they can edit scripts to better meet requirements.

First I tried petermad's solution because it has been more understandable for me and next I have just tested your vbs solution (vbs is not so understandable for me).

vbs solution:

It works good. Important difference is that OS Windows does deleting not TC and the descript.ion files bound with deleted empty folders are not deleted. Sometimes it is needed just so sometimes not. Advantage is that no plugin is needed.

I would like to request in vbs:
1) in the begining a question could show like:
Are you sure, you want to delete empty folders in <path> ?
Yes / No
(reason is if user clicks button by mistake or if path is wrong by mistake he can stop it)
2) if done, number of deleted folders would be showed:
Done. XX empty folders were deleted.
(reason: to know what was done, if there were empty folders or not)
3) "done" message not be autodisappered.
(reason: to see result)
(yes, I have wanted one-click solution, but before and after process there can be some dialog with user for reasons I have mentioned above)

Once more, thanks to all advisers, everything is helpful.
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 »

oko wrote: ↑2022-05-25, 08:24 UTCI would like to request in vbs:

Code: Select all

'β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” VBS β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
' Recursive deletion of empty subdirectories
' Parameter: "<folder path>" (for example, "%P")
'β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
Option Explicit: Dim Dir, FSO, Col, D, c, Msg
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: Quit
If MsgBox("Execute in """ & Dir & """?", 262180, Title) = 7 Then Quit
Recursion FSO.GetFolder("\\?\" & Dir)
Col.Sort : Col.Reverse
For Each D in Col
   Set D = FSO.GetFolder(D)
   If D.SubFolders.Count + D.Files.Count = 0 Then c = c + 1: D.Delete 1
Next
If c Then Msg = "  Done!" & vbLf &_
"  Count of deleted: " & c Else Msg = "No empty subfolders found."
MsgBox Msg, 262208, Title: Quit
Sub Quit : Set FSO = Nothing : Set Col = Nothing : WSH.Quit : End Sub

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 c = c + 1: D.Delete 1
  Next
End Sub
Overquoting is evil! πŸ‘Ž
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 »

In my "solution" (via Xxcopy) the /yy key stands for (literally)
Suppresses nearly all prompts (good for batch scripts)
You should test the Xxcopy command with/without the /yy key, and for folder with/without the description
Single user license #329241
PowerPro scripts for Total Commander
Anselm
Junior Member
Junior Member
Posts: 31
Joined: 2013-09-17, 17:06 UTC

Re: Delete empty folders (one-click function)

Post by *Anselm »

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
I tried this (only at windows command line), so i can give some additional information:
  • development of xxcopy was discontinued
  • is is not free for commercial use
  • it is free for personal use
  • the installation copies files to \windows\system32
    1. Copied C:\WINDOWS\system32\XXCOPYSU.EXE
    2. Copied C:\WINDOWS\system32\XXPBAR64.EXE
    3. Copied C:\WINDOWS\system32\XXCONSOLE.EXE
    4. Copied C:\WINDOWS\system32\UIXXCOPY.BAT
    5. Copied C:\WINDOWS\system32\XXCOPY.CHM
It does not work with long path names, example:

Code: Select all

mkdir d:\1\2\a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
move d:\1\2 d:\1\b123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567

Code: Select all

xxcopy.exe d:\1 /rmdir /x*.* /yy
Anselm
Junior Member
Junior Member
Posts: 31
Joined: 2013-09-17, 17:06 UTC

Re: Delete empty folders (one-click function)

Post by *Anselm »

robocopy seems to work with long path names:

create example folder:

Code: Select all

mkdir d:\1\2\a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
move d:\1\2 d:\1\b123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
removing empty folders (example):

Code: Select all

robocopy d:\1 d:\1 /S /MOVE /NDL
Post Reply