Page 3 of 4
Re: Delete empty folders (one-click function)
Posted: 2022-05-26, 17:34 UTC
by Vochomurka
Anselm wrote: 2022-05-26, 12:44 UTC
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
- Copied C:\WINDOWS\system32\XXCOPYSU.EXE
- Copied C:\WINDOWS\system32\XXPBAR64.EXE
- Copied C:\WINDOWS\system32\XXCONSOLE.EXE
- Copied C:\WINDOWS\system32\UIXXCOPY.BAT
- 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
1. Yes, development was discontinued, and I've never stated the opposite. Nevertheless the program works;
2. True; so what?
3. I am a person, you seem to be one, too;
4. These are just default paths; they can be changed at the installation. Run Install.bat and read instructions;
5. It does; read the documentation about the /VL key. Max path length is 32767 characters
Re: Delete empty folders (one-click function)
Posted: 2022-05-26, 18:16 UTC
by Horst.Epp
Vochomurka wrote: 2022-05-21, 16:45 UTC
I use
Xxcopy tool for this purpose. I created batch file with one line
It's exactly one-click button
If you change xxcopy.exe to xxcopysu.exe you can avoid the UAC prompt.
Re: Delete empty folders (one-click function)
Posted: 2022-05-27, 01:38 UTC
by Fla$her
Anselm wrote: 2022-05-26, 12:50 UTCremoving empty folders (example):
So he will delete folder 1 itself if it turns out to be empty. Need like this:
Code: Select all
%ComSpec% /q/c cd/d d:\1&robocopy d:\1 d:\1 /s /move /ndl /nfl /njh /njs
Re: Delete empty folders (one-click function)
Posted: 2022-10-30, 14:50 UTC
by beb
Working user command aimed to delete any empty (sub)directories within the current directory in the active panel:
Code: Select all
[em_deletemptydirs]
cmd=robocopy . . /s /move /NFL /NDL /NJH /NJS
or, respecting the "%ComSpec% /q/c >nul" part in front according to
Fla$her
Code: Select all
[em_deletemptydirs]
cmd=%ComSpec% /q/c>nul robocopy . . /s /move /NFL /NDL /NJH /NJS
Such a command can be placed by a user either in a button bar or in a menu.
From here:
viewtopic.php?p=423466#p423466
Re: Delete empty folders (one-click function)
Posted: 2023-04-23, 13:09 UTC
by beb
Fully PowerShell-powered one-click user command to recursively delete any empty (sub)directories within the current directory in the active panel:
button:
Code: Select all
TOTALCMD#BAR#DATA
em_delEmptyDirs
wciconex.dll,85
DeleteEmptyDirs
0
10030
usercmd.ini:
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
usercmd.ini (the same as above in full syntax without any aliases and contractions, thus the longest version):
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
NB 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). PowerShell-powered command doesn't have such a flaw.
Re: Delete empty folders (one-click function)
Posted: 2023-09-20, 06:41 UTC
by KozakMak
let's complicate the task
delete any empty (sub)directories within the current directory in the active panel to
recycle bin
any ideas?
Re: Delete empty folders (one-click function)
Posted: 2023-09-20, 09:09 UTC
by beb
KozakMak wrote: 2023-09-20, 06:41 UTC
delete any empty (sub)directories within the current directory in the active panel...
No problem,
I do it this way [without any 3rd party tools, and robocopy, which I don't recommend]:
usercmd.ini
[TotalCommander .ini only, no standalone .ps1 PowerShell script needed]
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
As far as I know, this is the best and the only effectively legit way to do it properly in PowerShell, in one pass and without any side-effects described here and there.
NB Unaliased code for better reading and understanding:
[deleting empty directories within the current directory from a standalone .ps1 PowerShell script]:
Code: Select all
Get-ChildItem (Get-Location) -force -recurse|Where {$_.PSIsContainer -and @(Get-ChildItem -literalPath $_.Fullname -force -recurse|Where {!$_.PSIsContainer}).Length -eq 0}|Remove-Item -force -recurse
KozakMak wrote: 2023-09-20, 06:41 UTC
... to
recycle bin
Not sure about this part -- I don't utilize RecycleBin on my PCs.
Though, as I may assume if the RecycleBin is turned on it's a system-wise property, that affects all the common applications, including PowerShell Remove-Item a.k.a. del. Just check the above command and you will see.
Re: Delete empty folders (one-click function)
Posted: 2023-09-20, 10:18 UTC
by KozakMak
2
beb
https://ibb.co/xqDr5my
must be run as elevated for some dirs
...and of course recycle bin was bypassed
Re: Delete empty folders (one-click function)
Posted: 2023-09-20, 19:52 UTC
by beb
KozakMak wrote: 2023-09-20, 10:18 UTC
...and of course recycle bin was bypassed
Feel free to try modifying the script to fit your needs regarding the relevant lookup results:
Google: PowerShell move folders to recycle bin
NB Out of curiosity, couldn't you be so kind as to remove this ritual "sorry for my poor English" from your signature, sinse it's just ridiculous.
Google: stop apologizing for bad English
Edit:
С:\Users\admin\AppData\...
By the way,
I strongly do not recommend to nonchalantly
carpet bombing locations alike %UserProfile%, %AppData% with such commands without proper consideration on where exactly you are and what exactly you are going to do. There are a bunch of pretty dumb apps that can store sensitive structures there (even represented by some seemingly aimless empty folders) and just would refuse to start anymore if you delete even the empty folders that were meant to belong to them to work, and they won't ever start again until you recreate the appropriate structures exactly as required (from the backups, or manually), or until you reinstall them.
Re: Delete empty folders (one-click function)
Posted: 2023-09-21, 08:40 UTC
by KozakMak
beb wrote: 2023-09-20, 19:52 UTC
and what exactly you are going to do.
циган знає що кобилі робить
I know what i'm doing
As a conclusion, I see that at the moment there are no transparent and safe solutions in this matter.
It should be something like
RED:
- a list of everything that will be deleted should be displayed
- recycle bin must be used
- there should be error handling
...even TotalCmd with plugin search doesn't handle it correctly - try searching in %temp% and then deleting folder with write permission.
Re: Delete empty folders (one-click function)
Posted: 2023-09-21, 20:08 UTC
by beb
2
KozakMak
PowerShell_DeletEmptyFolders_withLog_example.ps1
Code: Select all
"";"displaying working directory:";([System.Environment]::CurrentDirectory)
"";"deleting empty directories..."
$stamp = (Get-Date -format "yyyyMMdd_HHmmssf");$log = $($stamp+'_del.log')
$output = $(Get-ChildItem (Get-Location) -force -recurse|Where {$_.PSIsContainer -and @(Get-ChildItem -literalPath $_.Fullname -force -recurse|Where {!$_.PSIsContainer}).Length -eq 0}|Remove-Item -force -recurse -Verbose -ErrorAction Ignore) 4>&1
"";"displaying deleted folders:";$output|Tee-Object $log -Append
"";"deleted folders logged in:";$log
"";pause
- a list of everything that will be deleted should be displayed
All the deleted empty folders are displayed in the example script.
- recycle bin must be used
What's the point? No way, this crap is not for me.
Instead, all the deleted folders are listed in the log file and can be restored by their full paths if needed.
- there should be error handling
In the example script error handling is simple -- ignore.
You can modify this script according to your needs, for instance:
PowerShell_DeletEmptyFolders_withLog_example_v2.ps1
Code: Select all
"";"displaying working directory:";([System.Environment]::CurrentDirectory)
"";"locating empty folders that can be deleted..."
$stamp = (Get-Date -format "yyyyMMdd_HHmmssf");$log = $($stamp+'_del.log')
$output = $(Get-ChildItem (Get-Location) -force -recurse|Where {$_.PSIsContainer -and @(Get-ChildItem -literalPath $_.Fullname -force -recurse|Where {!$_.PSIsContainer}).Length -eq 0}|Select-Object -ExpandProperty FullName|Out-File $log -Append) 4>&1
"";"displaying empty folders that can be deleted:";Get-Content($log)
This script locates all the empty folders that can be deleted, displays them, and saves their paths in the log file.
Then you can add a part to just delete those folders (or some of them) using their list in the log file.
Re: Delete empty folders (one-click function)
Posted: 2023-09-22, 08:49 UTC
by KozakMak
for myself I decided to settle on this solution with .reg-menu
Code: Select all
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\del empty dirs\command]
@="cmd.exe /K for /f \"usebackq delims=\" %%d in (`\"dir \"%V\" /ad/b/s | sort /R\"`) do rd \"%%~d\""
Re: Delete empty folders (one-click function)
Posted: 2023-09-22, 11:12 UTC
by beb
2
KozakMak
PowerShell_DeletEmptyFolders_Display_Log_Remove.ps1
Code: Select all
"creating test folders structure:"
$md = '.\empty\empty' ;New-Item $md -force -Type directory >$null; $md
$md = '.\empty\folder' ;New-Item $md -force -Type directory >$null; $md
$md = '.\empty\structure';New-Item $md -force -Type directory >$null; $md
$md = '.\empty\file.txt' ;New-Item $md -force -Type file -value "file">$null; $md
"";"working directory:";([System.Environment]::CurrentDirectory)
"";"empty folders that can be deleted:"
$stamp = (Get-Date -format "yyyyMMdd_HHmmssf");$log = $($stamp+'_del.log')
Get-ChildItem (Get-Location) -force -recurse|Where {$_.PSIsContainer -and @(Get-ChildItem -literalPath $_.Fullname -force -recurse|Where {!$_.PSIsContainer}).Length -eq 0}|Select-Object -ExpandProperty FullName|Out-File $log
Get-Content($log)
"";"empty folders actually being deleted:"
Get-ChildItem (Get-Location) -force -recurse|Where {$_.PSIsContainer -and @(Get-ChildItem -literalPath $_.Fullname -force -recurse|Where {!$_.PSIsContainer}).Length -eq 0}|Remove-Item -force -recurse -Verbose -ErrorAction Ignore 4>&1
"";"see deleted folders list in a log file:";$log
"";pause
Example script output:
https://i.imgur.com/9l9QcSA.png
Re: Delete empty folders (one-click function)
Posted: 2023-09-22, 11:33 UTC
by KozakMak
working directory - must be %P for button
Re: Delete empty folders (one-click function)
Posted: 2023-09-22, 12:13 UTC
by beb
working directory - must be %P for button
Nope. If your "working directory" implies it is a directory opened in the active panel, you don't need to pass any parameters to the script at all.
Just try a button like this:
Code: Select all
TOTALCMD#BAR#DATA
PowerShell y:\our\path\to\the\script\PowerShell_DeletEmptyFolders_Display_Log_Remove.ps1
TOTALCMD.EXE
PowerShell_DeletEmptyFolders_Display_Log_Remove
0
-1