Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single Post  Topic: Групповая модификация времени изменения с помощью счётчика 
Author Message
helb



PostPosted: Wed Apr 27, 2016 23:50    Post subject: Reply with quote

Пара фиксов и индикация неудачных попыток.

reoder-timestamps.ps1:
Code:
<#   Reorder Timestamps [by helb] v2015-11-08
   Adjusts timestamps of listed items to reflect list order from oldest to newest
   Корректирует время модификации указанных объектов по возрастанию в соответсвии с их порядком
   Usage: “<list file (UTF-8)>”
   Total Commander list parameter: %UL
#>
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

function msgBx($text, $title, $btns = 0) {
   return [System.Windows.Forms.MessageBox]::Show($text, $title, $btns)
}

function lowerThanRemaining($idx) {
   $ts = $f[$idx].time
   for ($j = $idx+1; $j -lt $f.length; $j++) {
      if ($f[$j].time -lt $ts) { return $false }
   }
   return $true
}

function setTimestamp($path, $time) {
    $file = get-item -LiteralPath $path -force
    $ro = $file.IsReadOnly
    $file.IsReadOnly = $false
    $file.LastWriteTime = $time
    if ($ro) { $file.IsReadOnly = $true }
}

if ($args.length -lt 1) { msgBx "No parameters." "Error"; return }
$list = [environment]::ExpandEnvironmentVariables($args[0])

if (!(test-path -literalPath $list)) { msgBx "List file not found." "Warning"; return }
[array]$files = get-content $list | where-object { (test-path -literalPath $_) }
if ($files.length -lt 2) { msgBx "Too few files" "Error"; return }
$f = @()
foreach ($entry in $files) {
   $file = get-item -literalPath $entry -force
   $fl = new-object System.Object
   $fl | add-member -type NoteProperty -name obj -value $file
   $fl | add-member -type NoteProperty -name time -value $file.LastWriteTime
   $f = $f + $fl
}

do {
   $cnt = 0
   $low = $prevstamp = $f[0].time
   for ($i = 1; $i -lt $f.length - 1; $i++) {
      if ($f[$i].time -le $prevstamp) {
         $prevstamp = $prevstamp.AddSeconds(1)
         $f[$i].time = $prevstamp
         $cnt++
      }
      elseif ($f[$i].time -gt $f[$i+1].time) {
         if ($f[$i+1].time.AddSeconds(-1) -gt $prevstamp) {
            $prevstamp = $f[$i+1].time.AddSeconds(-1)
            $f[$i].time = $prevstamp
         }
         else {
            if ($f[$i+1].time.AddSeconds(-1) -le $low) { $prevstamp = $low.AddSeconds(1) }
            else { $prevstamp = $f[$i+1].time.AddSeconds(-1) }
            $f[$i].time = $prevstamp
         }
         $cnt++
      }
      else {$prevstamp = $f[$i].time}
      if ($cnt -eq 0) {
         if (lowerThanRemaining $i) { $low = $prevstamp }
      }
   }
   if ($f[$i].time -le $prevstamp) {
      $prevstamp = $prevstamp.AddSeconds(1)
      $f[$i].time = $prevstamp
      $cnt++
   }
} while ($cnt -gt 0)
$errs = 0
foreach ($fl in $f) {
try{
    setTimestamp $fl.obj $fl.time
} catch {
    $errs++
}
}
if ($errs) { MsgBx("Failed setting timestamp on "+ $errs + "/" + $f.length) }
View user's profile Send private message


Powered by phpBB © 2001, 2005 phpBB Group