Delete files with keeping the folder date

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1013
Joined: 2004-07-29, 11:00 UTC

Delete files with keeping the folder date

Post by *ZoSTeR »

 
Not really a plugin/addon but it might be useful to somebody:

I often delete specific files in my download subfolders (via Ctrl+B / File-Search) but this updates the modified date of the parent folder and thereby messing up the sort-by-date order.

This a little PowerShell script to avoid that:

Code: Select all

#TC Button
<#--------------------snip------------------
TOTALCMD#BAR#DATA
powershell.exe
-ExecutionPolicy remotesigned -Command "& {& """${env:COMMANDER_PATH}\Tools\DeleteWithDateRestore.ps1""" -ListFile '%UL'}"
C:\WINDOWS\System32\imageres.dll,322
Delete with Date Restore


-1

--------------------end-snip----------------#>
#TC Button End


param(
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$ListFile
)

$files = Get-Content -LiteralPath $ListFile

$answer = Read-Host -Prompt "Delete $($files.count) files? (y)"

if (@("y","j") -contains $answer)
{
    foreach ($file in $files)
    {
        if (Test-Path -LiteralPath $file -PathType Leaf)
        {
            $item = Get-Item -LiteralPath $file
            $parentLastWriteTime = $item.Directory.LastWriteTime
            $item.Delete()
            $item.Directory.LastWriteTime = $parentLastWriteTime
        }
    }
}
else
{
    #throw "Abort"
    return
}
Save as "~TC-Path~\Tools\DeleteWithDateRestore.ps1" or adjust the path to your liking and copy&paste the snip part as a button.

Select the files to delete and hit the button.
Post Reply