我正在尝试使用 powershell 复制一些名称与过滤器匹配的目录。
首先,我删除了在目标路径中匹配的所有目录,之后我尝试复制源目录和内容,但我遇到了问题,因为只复制了目录和子目录中的文件,而不是目录名称和结构。
$source="F:\origin"
$destination="F:\dest"
$filter="@"
# Remove dirs @
Get-ChildItem -Path $destination -Recurse |
Where-Object { $_.DirectoryName -match $filter } |
remove-item -Recurse
# Copy dirs and all contents
Get-ChildItem -Path $source -Recurse |
Where-Object { $_.DirectoryName -match $filter } |
Copy-Item -Destination $destination
我怎样才能做到这一点 ?
谢谢
编辑
F:\origin\@test\index.php
F:\origin\@test1\index1.php
F:\origin\@test1\sub1\subindex1.php
F:\origin\no_consider\index1.php
预期输出
F:\dest\@test\index.php
F:\dest\@test1\index1.php
F:\dest\@test1\sub1\subindex1.php