如何复制整个目录结构? [英] How to copy entire directory structure?

查看:48
本文介绍了如何复制整个目录结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 10,000 个文件从一个目录复制到另一个目录.

I am copying 10,000 files from one directory to another directory.

两个目录结构都有相同的文件;但是,尺寸可能会有所不同.

Both directory structures have the same files; however, the sizes might be different.

如何强制覆盖不同大小的文件,并且不复制相同大小的文件?

How do I force overwriting on files that have different sizes and DO NOT copy files that are the same size?

到目前为止,我有这个:

So far I have this:

$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"
  }
}

我认为这会复制目标上不存在的文件.但是,我也想复制确实存在但大小不同的文件.

I think that will copy files that do not exist on the destination. However, I also want to copy files that DO exist but where their size differs.

推荐答案

使用 robocopy 而不是尝试在 PowerShell 中重新发明它.

Use robocopy instead of trying to re-invent it in PowerShell.

robocopy D:\Test1 D:\Test2 /s

如果您还想包含仅属性不同的文件(调整后的文件"),请同时添加 /it.

If you also want to include files where only attributes differ ("tweaked files"), add /it as well.

这篇关于如何复制整个目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆