【发布时间】:2018-09-07 02:07:14
【问题描述】:
我正在尝试使用 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
【问题讨论】:
-
您能否添加文件夹示例列表和预期输出?
-
这可能就像添加
Recurse一样简单,所以它会复制目录的内容?Copy-Item -Destination $destination -Recurse -
@JamesC - -recurse 不工作..
标签: powershell