TotalCommander plus PowerShell plus 7zip: redate archive(s) regarding its latest content

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

TotalCommander plus PowerShell plus 7zip: redate archive(s) regarding its latest content

Post by *beb »

TotalCommander plus PowerShell plus 7zip: redate archive(s) regarding its latest content (i.e. setting an archive timestamp from the most recently modified file within)

Example use case:

Let's say, I have a bunch of random archives which I-got-from-who-knows-where-from and may-have-got-who-knos-what-timestamps.

By design, an archive may have its external timestamp reflecting the time it was saved, downloaded, etc.

What if:
I wish an archive to be kept under its content's date (i.e. having a timestamp reflecting the most recently modified content within).

A user-button:

Code: Select all

TOTALCMD#BAR#DATA
em_redate_archives_by_content

TOTALCMD64.EXE,41
PowerShell: Redate archives by content

0
-1
User-command (usercmd.ini):

Code: Select all

[em_redate_archives_by_content]
cmd=pwsh -c "%commander_path%\Plugins\app\PowerShell\redateArchivesContent.ps1"
PowerShell script (redateFilesPattern.ps1):

Code: Select all

$lap   = [system.diagnostics.stopwatch]::StartNew()
# binary
$env:path += ";$env:commander_path\Plugins\app\7zip"
# define files
$zip   = @('*.zip','*.7z','*.epub')
$files = Get-ChildItem * -file -force -include $zip
# process
foreach ($file in $files) {
$i     = $file.FullName
$name  = $file.Name
Write-Host "processing..." -f Yellow
Write-Host "full : $i"     -f Cyan
Write-Host "name : $name"  -f Cyan
# 7zip list output date pattern
$date  = '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'
$array = (&7z l $i | Where {$_ -match $date}).substring(0,19)
Write-Host "measure..." -f Yellow
$min   = ($array|Measure-Object -Min).Minimum;"min  : $min"|Write-Host -f Green
$max   = ($array|Measure-Object -Max).Maximum;"max  : $max"|Write-Host -f DarkCyan
(Get-Item $i).LastWriteTime = Get-Date $max;''
}
$lap.Stop();'';"timer: {0:mm}:{0:ss}.{0:fff}" -f $lap.Elapsed|Write-Host -f Cyan;sleep -s 5
Notes:
- Since TC 11.50 betas Mr ghisler(Author) is trying their best to integrate 7zip, but I don't have time to recognize how it works in practice, so the above script implies using standalone 7zip.
- The script in no way modifies the archives' content (they will digitally remain the same), only their external timestamps.
- Given script edition implies it will process *.zip, *.7z', and *.epub archives. Feel free to add there other zip-based archives from which 7zip l is capable of extracting the adequate tramp stamps (*.docx, *.xlsx. etc).
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6951
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: TotalCommander plus PowerShell plus 7zip: redate archive(s) regarding its latest content

Post by *Horst.Epp »

A simple solution is to use only 7zG.exe like this

Code: Select all

TOTALCMD#BAR#DATA
"C:\Program Files\7-Zip\7zG.exe"
rn %P%N : : -stl
"C:\Program Files\7-Zip\7zG.exe"
Set archive date to newest file

0
-1
Windows 11 Home, Version 24H2 (OS Build 26100.3915)
TC 11.51 x64 / x86
Everything 1.5.0.1391a (x64), Everything Toolbar 1.5.2.0, Listary Pro 6.3.2.88
QAP 11.6.4.2.1 x64
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: TotalCommander plus PowerShell plus 7zip: redate archive(s) regarding its latest content

Post by *beb »

2Horst.Epp
Thank you very much for sharing.
I didn't know the 7zip rn (rename) command could work this way.
I tried it. Console 7z.exe here does the same thing too.
So,
7zG.exe rn archive.zip : : -stl
7z.exe rn archive.zip : : -stl
and my script give identical results, thus it is reasonable for a user to prefer a simpler pure 7zip solution.
I am definitely going to change my script regarding that info, abandoning its current version.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
petermad
Power Member
Power Member
Posts: 15999
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: TotalCommander plus PowerShell plus 7zip: redate archive(s) regarding its latest content

Post by *petermad »

2beb

I use this TC-only approach (should work for all archives, that TC can open as a folder):

usercmd.ini

Code: Select all

[em_setArcDate0]
cmd=cd
param=%T%M\

[em_setArcDate1]
cmd=OPENATTRIBUTES =+L2

[em_setArcDate]
cmd=cm_FocusTrg,cm_SrcByName 8,cm_OpenNewTab,em_setArcDate0,cm_DirBranch,cm_SrcByDateTime 2,cm_GoToFirstFile,cm_FocusTrg,cm_ClearAll,em_setArcDate1,cm_FocusTrg,cm_GoToPreviousDir,cm_CloseCurrentTab,cm_SrcByName 9,cm_FocusTrg
menu=Sæt arkivdato til seneste fildato
button=wcmicons.dll,33
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: TotalCommander plus PowerShell plus 7zip: redate archive(s) regarding its latest content

Post by *beb »

2petermad
This is just something supernatural.
Can't believe a fellow human could make such a thing.
I have no words.
Respect!
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Post Reply