我需要复制一个名为“SystemData”的文件夹,该文件夹位于其他文件夹中,并且从该“SystemData”文件夹中我有许多 *.xml 文件。我想将 *.xml 文件复制到另一个位置,同时保留文件夹结构。我一直在尝试使用 robocopy 来做到这一点,但惨败。
我想知道是否有人可以帮助我使用 robocopy 创建一个 powershell 脚本,将该文件夹中的 *.xml 文件复制到另一个位置,同时保留文件夹结构
感谢您的帮助。
我正在使用这段代码,但文件夹结构没有保留,这让我很沮丧。有什么想法如何在那里添加文件夹结构吗?
$dest = "C:\Users\peter.franca\Desktop\CopiedFiles\ProcessedProducts"
$source = "C:\Users\peter.franca\Desktop\ProcessedProducts"
$files = Get-ChildItem $source -File -include "*.xml" -Recurse | Where-Object { $_.DirectoryName -like "*SystemData*" }
Copy-Item -Path $files -Destination $dest -Recurse -Container
Copy-Item -Path "$source" -Destination "$dest" -Verbose -Force -filter "*.xml" -Recurse
如果源是文件夹,Copy-Item 将为您创建文件夹