简体   繁体   English

如何复制整个目录结构?

[英]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. 但是,我还想复制存在但文件大小不同的文件。

Use robocopy instead of trying to re-invent it in PowerShell. 使用robocopy而不是尝试在PowerShell中重新创建它。

robocopy D:\Test1 D:\Test2 /s

If you also want to include files where only attributes differ ("tweaked files"), add /it as well. 如果您还想包含只有属性不同的文件(“调整文件”),也可以添加/it

我想检查$ sourcelist文件LastWrite时间戳,然后将它与目标文件时间戳进行比较。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复制目录并创建上层目录结构 - Copy directory and create upper directory structure 如何递归复制目录结构并仅复制底层中的文件(Windows Batch) - How can I recursivly copy a directory structure and only copy the files in the bottom tier (Windows Batch) 如何复制目录结构但只包含某些文件(使用 Windows 批处理文件) - How to copy a directory structure but only include certain files (using windows batch files) 如何将所有子目录的内容复制到一个目录中,保留结构并用批处理文件覆盖重复项? - How to copy the contents of all subdirectories into one directory, retaining structure and overwriting duplicates with a batch file? 在Windows批处理中复制单个文件而不是整个目录 - Copy single file instead of entire directory in windows batch 使用XCopy将具有精确结构的文件复制到另一个目录中 - Copy Files with exact Structure into another Directory using XCopy 如何在Powershell中下载整个Dropbox目录? - How to download an entire dropbox directory in powershell? 如何使用 PowerShell 2.0 递归删除整个目录? - How to recursively delete an entire directory with PowerShell 2.0? Windows cmd:复制整个目录*包括*父目录。 不指定相同父目录名称的解决方案 - Windows cmd: Copy over entire directory *including* parent directory. Solution without specifying same parent directory name 搜索字符串可能会在整个目录结构的特定文件类型中包含空格和特殊字符 - Search for a string may containing spaces and special characters in the specific type of files in entire directory structure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM