【发布时间】:2019-03-06 11:19:35
【问题描述】:
我想将某种类型的所有文件从某个子目录及其相对路径从该子目录复制到另一个目录,并且相对路径完好无损。例如:
源子目录:
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}
但是,这种“一切都是对象”à la PowerShell 让我失望(至少我怀疑是这样)。 IE。文件被复制,但没有它们的相对路径。
谁能给我一点启示?
【问题讨论】:
-
“谁能给我一点启发?” - 看起来微软采取了一些简单的工作,并将其复杂到不再工作的地步。当开发人员不得不上网并查找如何使用复制命令时,这很可悲。对微软来说,这是一场史诗般的工程失败。
-
@jww 伙计,你在说什么?常规复制命令不会使用相对路径复制文件,并且永远不会复制。这总是需要编写脚本或使用
xcopy、robocopy、rsync等专用工具。
标签: powershell