簡體   English   中英

如何復制整個目錄結構?

[英]How to copy entire directory structure?

我將10,000個文件從一個目錄復制到另一個目錄。

兩個目錄結構都有相同的文件; 但是,尺寸可能會有所不同。

如何強制覆蓋具有不同大小的文件並且不要復制大小相同的文件?

到目前為止我有這個:

$source = 'D:\Test1'
$destination = 'D:\test2'
$exclude = @('*.db','test2.log')
$sourcelist = Get-ChildItem $source -exclude $exclude
foreach ($file in $sourcelist){
  $result = test-path -path "$destination\*" -include $file
  if ($result -like "False"){
    #uncomment the next line to see the value being passed to the $file parameter
    #Write-Host $file
    Copy-Item "$file" -Destination "$destination"
  }
}

我認為這將復制目標上不存在的文件。 但是,我還想復制存在但文件大小不同的文件。

使用robocopy而不是嘗試在PowerShell中重新創建它。

robocopy D:\Test1 D:\Test2 /s

如果您還想包含只有屬性不同的文件(“調整文件”),也可以添加/it

我想檢查$ sourcelist文件LastWrite時間戳,然后將它與目標文件時間戳進行比較。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM