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:35    Post subject: Reply with quote

Актуальная версия с фиксом для read-only атрибута:
Code:
<#   Keep Timestamps [by helb] v2015-12-07
   Сохраняет атрибуты указанных файлов и папок в CSV-файл или восстанавливает из него
   Использование: “<list file (UTF-8)> [/r]” или “/l” (l=восстановить, r=рекурсивно)
   Saves attributes of listed items to a CSV file or restores saved ones
   Usage: “<list file (UTF-8)> [/r]” or “/l” (l=load(restore), r=recursively)
   Total Commander list parameter: %UL
#>
$attributeFile = "%TEMP%\attributes-B3B2CFDF-AE75-4112-B6C4-239982E09E7D.tmp"
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

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

if ($args.length -lt 1) { msgBx "No parameters." "Error"; return }
if ($args[0] -eq "/l") {$restore = $true}
else {
   $list = [environment]::ExpandEnvironmentVariables($args[0])
   if ($args[1] -and $args[1] -eq "/r") {$recurse = $true}
}

$attributeFile = [environment]::ExpandEnvironmentVariables($attributeFile)
if ($restore){
   if (!(test-path -literalPath $attributeFile)) { msgBx "No timestamp file." "Error"; return }
   [array]$files = import-csv $attributeFile -delimiter "`t"
   foreach ($entry in $files){
      if (test-path -literalPath $entry.FullName){
         $file = get-item -literalPath $entry.FullName -force
         $file.IsReadOnly = $false
         $file.CreationTime = $entry.CreationTime
         $file.LastWriteTime = $entry.LastWriteTime
         $file.LastAccessTime = $entry.LastAccessTime
         $file.Attributes = $entry.Attributes
      }
   }
}
elseif (!(test-path -literalPath $list)) { msgBx "List file not found." "Warning"; return }
else {
   $files = @()
   $filelist = get-content $list
   foreach ($name in $filelist) {
      if (test-path -literalPath $name) {
         $files += get-item -literalPath $name -force
         if ($recurse) {
            $tmpfiles = get-childItem -literalPath $name -recurse -force #| sort-object FullName
            if (!($tmpfiles.FullName -and $tmpfiles.FullName -eq $name)) {$files += $tmpfiles}
         }
      }
   }
   $files | select FullName, CreationTime, LastWriteTime, LastAccessTime, Attributes | export-csv $attributeFile -force -delimiter "`t" -encoding "UTF8"
}
View user's profile Send private message


Powered by phpBB © 2001, 2005 phpBB Group