2beb
Yes, there is. Well, use my script then.
Find & Delete Empty Folders
Moderators: Hacker, petermad, Stefan2, white
Re: Find & Delete Empty Folders
Overquoting is evil! 👎
Re: Find & Delete Empty Folders
After a couple of days of experiments I may say that the said issue regarding special folders' possible attributes drop-off can be partially addressed as follows:beb wrote: 2022-11-01, 12:56 UTC It turns out the [robocopy '"dir1" "dir1" /s /move] command is resulting in dropping off all the attributes of the source folders (R - Read only; S - System; H - Hidden) if any, except A (Archive)
TotalCommander user command:
Code: Select all
[em_delemptydirs]
cmd=cmd /v /q/c>nul robocopy . . /s /move /NFL /NDL /NJH /NJS&for /f %i in ('dir /b/a/s . ^| find /i "desktop.ini"') do set d=%~dpi&attrib +r !d:~0,-1!
- cmd /v /q/c>nul part now has a /v switch that enables delayed environment variable expansion
- robocopy . . /s /move /NFL /NDL /NJH /NJS part does its intended job to delete all the empty dirs within the current dir in the active panel
- for /f %i in ('dir /b/a/s . ^| find /i "desktop.ini"') do set d=%~dpi&attrib +r !d:~0,-1! part:
- finds any folder containing desktop.ini file [dir /b/a/s . ^| find /i "desktop.ini"]
- detects the full path(s) of the said folder(s) [d=%~dpi]
- eliminates terminal backslash from the said path(s) [!d:~0,-1!] to properly feed it to the attrib command
note: this very part needs the "delayed environment variable expansion" to be turned on - sets the read-only attribute for the said folder(s) [attrib +r !d:~0,-1!]
note: it is assumed a directory that contains a "desktop.ini" file is rather a special folder,
so it is pretty reasonable to set (restore) the read-only attribute for it.
So, users would keep enjoying nice icons of such folders, or whatever.
For most users, it could be pretty enough regarding using the method in question.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Re: Find & Delete Empty Folders
Fully PowerShell-powered user command to recursively delete any empty (sub)directories within the current directory in the active panel:
button:
usercmd.ini:
usercmd.ini (the same as above in full syntax without any aliases and contractions, thus the longest version):
NB As seen, the above-mentioned robocopy-based command has a critical downside since it removes all the attributes of the folders (R - Read only; S - System; H - Hidden) if any, except A (Archive).
The PowerShell-powered command doesn't have such a flaw.
button:
Code: Select all
TOTALCMD#BAR#DATA
em_delEmptyDirs
wciconex.dll,85
DeleteEmptyDirs
0
10030
Code: Select all
[em_delEmptyDirs]
cmd=Powershell -ExecutionPolicy Bypass
param=ls (gl) -for -rec|Where {$_.PSIsContainer -and @(ls -lit $_.Fullname -for -rec|Where {!$_.PSIsContainer}).Length -eq 0}|del -for -rec
Code: Select all
[em_delEmptyDirs]
cmd=Powershell -ExecutionPolicy Bypass
param=Get-ChildItem (Get-Location) -force -recurse|Where {$_.PSIsContainer -and @(Get-ChildItem -literalPath $_.Fullname -force -recurse|Where {!$_.PSIsContainer}).Length -eq 0}|Remove-Item -force -recurse
The PowerShell-powered command doesn't have such a flaw.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15