TopPage

ファイル収集スクリプト

コピー元ディレクトリ配下の全ファイルをコピー先ディレクトリに重複排除、同名はリネームしながらコピーします。

使用方法

PowerShell? -F ./fCopy.ps1
fromDirとtoDirを指定します。

関連ページ


ファイル名: fCopy.ps1

[string]$fromDir = 
[string]$toDir = 
[string]$fName = ""
[string]$ext = ""
[string]$bName = ""
[int]$fCnt = 0
[int]$fSize = 0

Get-ChildItem $fromDir -Recurse -include *.* -Name | ForEach-Object { 

  $fName = @(Split-Path $_ -Leaf)
  if( Test-Path "$($toDir)\$($fName)" ) {
    $fSize =  (Get-ChildItem "$($fromDir)\$($_)").Length
    if( $fSize -eq (Get-ChildItem "$($toDir)\$($fName)").Length ) {
      echo "同一ファイルのためコピーしません。$($fromDir)\$($_) → $($toDir)\$($fName)"
      $fName = "dumm565656565"
    } else {
      $cnt = 0
      while( Test-Path "$($toDir)\$($fName)$($cnt.ToString("0000"))" ) {
        $cnt++
      }
      $ext = (Get-ChildItem "$($fromDir)\$($_)").Extension
      $bName = (Get-ChildItem "$($fromDir)\$($_)").BaseName
      $fName = "$($bName)_$($cnt.ToString("0000"))$($ext)"
    }
  }

  if( $fName -ne "dumm565656565" ){
    Copy-Item "$($fromDir)\$($_)" "$($toDir)\$($fName)"
    echo "コピーしました。$($fromDir)\$($_) → $($toDir)\$($fName)"
  }
}

参考ページ



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS