[英]How to copy entire directory structure?
I am copying 10,000 files from one directory to another directory. 我将10,000个文件从一个目录复制到另一个目录。
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. 但是,我还想复制存在但文件大小不同的文件。
我想检查$ sourcelist文件LastWrite时间戳,然后将它与目标文件时间戳进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.