Powershell 批量替換文件


Powershell 批量替換文件

##作者:Xiongpq
##時間:2015-06-10 18:50
##版本:2.0

##源文件目錄
##源文件目錄的所有文件都會覆蓋目標目錄的同名文件,源文件目錄可以在目標目錄內,不會循環覆蓋
$source = 'E:\Test_Target\Test_Source\'
##目標目錄,支持多個目錄
$target = 'E:\Test_Target\',
'D:\Test_Target'

$sourceItem = Get-ChildItem -Path $source -recurse

foreach ($sourceFileName in $sourceItem)
{
    $targetItem = Get-ChildItem -Path $target -include $sourceFileName.Name -recurse
    foreach ($targetFileName in $targetItem)
    {
        if ($targetFileName.FullName -ne $sourceFileName.FullName){
            Copy-Item -Path $sourceFileName.FullName -Destination $targetFileName.FullName -Force
        }        
    }
}
Write-Host("DONE.....................")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM