繁体   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