如何复制整个目录结构?
我正在将 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.