powershell - 不使用-Recurse将文件从一个文件夹移动到另一个文件夹

标签 powershell

我有一个powershell脚本,我要做的就是将某种类型的文件从指定的文件夹移动到目标文件夹。不幸的是,没有包含-Recurse的功能,这是行不通的,这不是我想要实现的功能。如果我包含-Recurse,它将开始从“D:/照片/ x /”等移动图像。我要做的就是将文件从“D:/照片”移动到目标位置。

Get-ChildItem "D:\Photos" -Include *.png, *.jpeg, *.jpg |
Move-Item -Destination "D:\Photos\Powershell Task" -Force

最佳答案

没有-Include-Recurse参数不起作用。

但是,还有另一种方法可以让-Include执行您想要的操作(即在多个扩展名上进行过滤),即在路径中添加\*

在您的情况下:

Get-ChildItem -Path "D:\Photos\*" -Include *.png, *.jpeg, *.jpg |
Move-Item -Destination "D:\Photos\Powershell Task" -Force

请注意:目标路径D:\Photos\Powershell Task必须存在。

关于powershell - 不使用-Recurse将文件从一个文件夹移动到另一个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54390006/

相关文章:

visual-studio-2010 - VS2010 构建后事件,替换文件中的字符串。电源外壳?

powershell - 导出模块成员 powershell 别名

powershell - 如何更改 PowerShell Cmdlet 的默认确认选项?

powershell - 在 Powershell 的 Export-Csv 中使用和不使用管道的区别

PowerShell中的SVN输出编码

powershell - 确定指定服务和插槽是否存在 Azure 部署

powershell - 从Windows CMD将数组传递到PowerShell

powershell - 格式表的标记字符串

powershell - 如何以逗号分隔的格式提取键值对的值?

powershell - 是否可以使用PowerShell cmdlet查看类的所有成员?