#author("2018-05-28T21:30:26+09:00","default:Authors","Authors")
#author("2018-05-29T00:10:45+09:00","default:Authors","Authors")
''[[TopPage]]''

* ファイル収集スクリプト [#t3e7ade7]
コピー元ディレクトリ配下の全ファイルをコピー先ディレクトリに重複排除、同名はリネームしながらコピーします。~

** 使用方法 [#y16642f4]
PowerShell -F ./fCopy.ps1~
fromDirとtoDirを指定します。~
ポリシーで実行できない場合はpowershell -ExecutionPolicy RemoteSigned~


** 関連ページ [#ib4c903e]
~

ファイル名: fCopy.ps1
 [string]$fromDir = 
 [string]$toDir = 
 [string]$fromDir = "G:\from"
 [string]$toDir = "G:\to"
 [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)"
   }
 }

*** 参考ページ [#y3729b39]
~
https://qiita.com/alchemist/items/e6706cd425f8f5e5032e~



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