Let's say, I have a folder with a bunch of subfolders with a certain content that has been remaining the same for the, i.e., last century.
Alas, regarding how the NTFS works, while the files' timestamps (if unchanged) will remain the same, the folders' timestamps are prone to be changed in a barely predicted manner (upon access, viewing, etc, even if the folders' file/data content itself remain unchanged).
So, here below is represented an approach for consistent timestamping of folders before, e.g., archiving, regardless of how the NTFS could redate them prior to the archiving over the course of time (otherwise archives with the same digital content [files] would differ only because the timestamps of the sub/folders within the root folder have been changed)...
User button:
Code: Select all
TOTALCMD#BAR#DATA
em_redate_folders_by_content
TOTALCMD64.EXE,41
PowerShell: Redate folders by content
0
-1
Code: Select all
[em_redate_folders_by_content]
cmd=pwsh -c "%commander_path%\Plugins\PowerShell\redateFoldersContent.ps1"
Code: Select all
$lap = [diagnostics.stopwatch]::StartNew()
$pwd.toString()
Get-ChildItem -force -recurse -directory|foreach {
Get-ChildItem -literal $_ -force -recurse -file|Measure -property LastWriteTime -maximum|Tee -var max|out-null
(Get-Item -literal $_.FullName).LastWriteTime = Get-Date $max.Maximum
"{0:yyyy}-{0:MM}-{0:dd} {0:hh}:{0:mm}:{0:ss} {1}" -f $_.LastWriteTime,$_.FullName.substring($pwd.toString().length+1)}
$lap.Stop();'';"Timer : {0:mm}:{0:ss}.{0:fff}" -f $lap.Elapsed;sleep -s 3
The script will work within the active TotalCommander's pane and redate each and every sub/folder (which would have timestamps after the latest file within).
Again, from my point of view, this is a must-have script to get consistent results regarding dating upon archiving not caring much about NTFS shenanigans. I use it as a standalone or a subscript, e.g. creating my *.epub(s), etc.:
ebook_make_epub_7zip.ps1
Code: Select all
# timer
$timer = [system.diagnostics.stopwatch]::StartNew()
# binary
$env:path += ";$env:commander_path\Plugins\app\7zip"
# define working folders
$input = [IO.Path]::Combine($pwd,'epub')
$print = [IO.Path]::Combine($pwd,'epub')
$skip = 'example'
if (-not ($print|Test-Path)){New-Item -type directory $print > $null}
$books = Get-ChildItem $input -directory -exclude $skip
if ($books.count -eq 0){
Write-Host "nothing to do here..." -f Yellow}
else {
# redate folders by the contents date
Write-Host "folders are being redated..." -f Green
Get-ChildItem $input -force -recurse -directory|foreach {
Get-ChildItem $_ -force -recurse -file|Measure -property LastWriteTime -maximum|Tee -var max|out-null # latest
(Get-Item $_).LastWriteTime = Get-Date $max.Maximum # latest
"{0} {1}" -f $_.Name,$_.LastWriteTime}
Write-Host "folders have been redated" -f Green
""
Write-Host ".epub books are being created..." -f Cyan}
# create ebooks
foreach ($book in $books) {
$i = $book.FullName
$name = $book.Name
""
Write-Host "processing..." -f Yellow
Write-Host "path : $i" -f Cyan
Write-Host "name : $name" -f Cyan
$epub = $($name+'.epub')
$to = $($print+'\'+$epub)
$from = $($input+'\'+$name+'\*')
# cleanup
if ($to|Test-Path){Remove-Item $to -force -recurse -EA Silent
Write-Host "cleanup... $epub (auld)" -f Magenta}
# epub make (pack)
&7z a -tzip -aoa -mmt -ssw -stl -ssp -y -mx9 "$to" "$from" 2>&1|where {$_ -match "Creating|Updating|Add new data|OK"}
}
# finalizing : timer and totals
$timer.Stop()
$total = $books.count
""
"timer: {0:mm}:{0:ss}.{0:fff}" -f $timer.Elapsed|Write-Host -f Cyan
""
"$total books processed"|Write-Host -f DarkCyan
""
pause