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: Копирование/вставка (Copy & Paste) атрибутов/времен файлов 
Author Message
helb



PostPosted: Thu Apr 28, 2016 00:47    Post subject: Копирование/вставка (Copy & Paste) атрибутов/времен файлов Reply with quote

Скрипт для копирования и вставки атрибутов файлов. Вешается на два хоткея (например Ctrl+Shift+D - Copy, Ctrl+Shift+F - Paste — по-близости от Ctrl+C/Ctrl+V). При копировании сохраняет только атрибуты (включая время) без имен файлов в файл в TEMP, которые впоследствии можно восстановить, и не обязательно на оригинальный(ые) файл(ы). Paste — при несоответствии числа выделенных файлов числу сохраненных предложит восстановить либо атрибуты одного файла на все выделенные, либо начальных из списка на все выделенные, если вторых меньше.

Запускать командой вида “powershell <имя.ps1> <параметры>”. PS должен быть установлен (актуально только для Win XP), и должно быть разрешено выполнение скриптов (единовременная команда “Set-ExecutionPolicy RemoteSigned” в среде PS)

copy-paste-attributes.ps1
Code:
<#   Copy-paste attributes [by helb] v2015-12-07
   Сохраняет атрибуты указанных файлов и папок (без соответствия имен) в CSV-файл (copy) или устанавливает из него (paste).
   Использование: “<list file (UTF-8)> [/r] [/p]” (p=вставить, r=рекурсивно)
   Saves attributes of listed files and folders (without name relation) to a CSV file (copy) or sets from previously saved ones (paste).
   Usage: “<list file (UTF-8)> [/r] [/p]” (p=paste, r=recursively)
   Total Commander list parameter: %UL
#>
$attributeFile = "%TEMP%\attributes-11e0d9f8-3a10-48be-a9f0-4e8984a2a7ca.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 }
foreach ($arg in $args) {
   if ($arg -eq "/p") {$restore = $true}
   elseif ($arg -eq "/r") {$recurse = $true}
   else {$list = [environment]::ExpandEnvironmentVariables($arg)}
}

if (!(test-path -literalPath $list)) { msgBx "List file not found." "Warning"; return }
else {
   $attributeFile = [environment]::ExpandEnvironmentVariables($attributeFile)
   $files = @()
   [array]$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}
         }
      }
   }
   if ($restore){
      if (!(test-path -literalPath $attributeFile)) { msgBx "No attribute file." "Error"; return }
      [array]$attributes = import-csv $attributeFile -delimiter "`t"
      $i = 0
      if ($files.length -le $attributes.length) {
         if ($files.length -lt $attributes.length){
            $re = msgBx "Number of listed files is lower than stored attributes. Proceed anyway?" "Warning" 4
            if ($re -ne "Yes") {
               return
            }
         }
         foreach ($file in $files) {
            if (test-path -literalPath $file.FullName) {
               $file.IsReadOnly = $false
               $file.CreationTime = $attributes[$i].CreationTime
               $file.LastWriteTime = $attributes[$i].LastWriteTime
               $file.LastAccessTime = $attributes[$i].LastAccessTime
               $file.Attributes = $attributes[$i].Attributes
            }
            $i++
         }
      }
      else {
         $re = msgBx "Number of listed files is greater than stored attributes. Paste first entry to everything?" "Warning" 4
         if ($re -eq "Yes") {
            foreach ($file in $files) {
               if (test-path -literalPath $file.FullName) {
                  $file.IsReadOnly = $false
                  $file.CreationTime = $attributes[0].CreationTime
                  $file.LastWriteTime = $attributes[0].LastWriteTime
                  $file.LastAccessTime = $attributes[0].LastAccessTime
                  $file.Attributes = $attributes[0].Attributes
               }
            }
         }
      }
   }
   else {
      $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