windows - 如何复制整个目录结构?

标签 windows powershell

我正在将 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

关于windows - 如何复制整个目录结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15562443/

相关文章:

node.js - Node : Check Machines OS while in Linux Bash on Windows 10

c++ - QFileDialog (QT 5.2.1/mingw32) 不允许我选择只读文件

excel - PowerShell - 将数据粘贴到 Excel 中

regex - PowerShell 从字符串中解析名称和版本

powershell - 导入 PSSession 在脚本中失败,在 shell 中工作

azure - PowerShell:如何判断用户是否有权从 Azure Key Vault 读取 secret ?

c++ - 给定一个 COM DLL,提取所有类 CLSID 和相应的接口(interface)名称

c# - 在 rtf 字符串的位置追加文本

windows - 创建 "fat"/"Universal"Windows DLL 在技术上是否可行?

winforms - 如何通过 VBS 将变量从一个 PS 脚本传递到另一个 PS 脚本?