如何在Powershell中将-recurse与Move-item一起使用

问题描述 投票:0回答:2

我创建了一个简单的 powershell 脚本,其中它将文件从源文件夹复制到具有相同目录结构的目标。

$source_path ="C:\Akash\Working\Source\*"

$backupPath="C:\Akash\Working\Dest"

copy-Item $source_path $backupPath  -Recurse   -EA "silentlycontinue"

它工作正常,但是当我尝试用 move-item 代替 copy-item 时,它会抛出一个错误:

Move-Item : A parameter cannot be found that matches parameter name 'Recurse'.

有人请在这里推荐...

powershell
2个回答
12
投票

Move-Item cmdlet 没有

-Recurse
开关。

这不是必需的,因为它已经复制了所有子项目:

Move-Item cmdlet 移动项目,包括其属性、内容、 和子项目,从一个位置到另一个位置。


0
投票

这应该符合你的需求,9年后......

Get-ChildItem -Path ".\*.txt" -Recurse | Move-Item -Destination A:\dest\
© www.soinside.com 2019 - 2024. All rights reserved.