我想将某个类型的所有文件从某个子目录及其相对路径从该子目录复制到另一个目录,并且相对路径完好无损。例如。:
源子目录:
c:\temp\sourcedirectory
源文件:
c:\temp\sourcedirectory\tonymontana\fileOne.txt
c:\temp\sourcedirectory\poker\fileTwo.txt
目标目录:
c:\temp\targetdirectory
想要的结果:
c:\temp\targetdirectory\tonymontana\fileOne.txt
c:\temp\targetdirectory\poker\fileTwo.txt
到目前为止,我想出了:
Set-Location $srcRoot
Get-ChildItem -Path $srcRoot -Filter $filePattern -Recurse |
Resolve-Path -Relative |
Copy-Item -Destination {Join-Path $buildroot $_.FullName}
但是,PowerShell 中的“一切都是对象”正在击败我(至少我怀疑是这样)。 IE。文件被复制,但没有它们的相对路径。
谁能给我一点启发?
最佳答案
不要为此使用 PowerShell cmdlet,只需使用 robocopy
:
robocopy C:\temp\sourcedirectory C:\temp\targetdirectory *.txt /s
关于powershell - 使用相对路径复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15616002/