首页 > 解决方案 > 如何使用 PowerShell 将具有多个扩展名的文件集移动到另一个目录?

问题描述

我需要将一组具有不同扩展名的特定文件移动到另一个文件夹。

我在目录中有以下过滤文件。

文件1.txt
文件2.xml
文件3.dll

我已将上述文件保存在变量中$files,我需要将每个文件移动到另一个文件夹。

下面是我试过的代码。

foreach ($fileType in $files) {
    Get-ChildItem -Path C:\Files -Filter "$fileType*." -Recurse |
        Move-Item -Destination C:\Dest
}

我收到以下错误

Get-ChildItem : 路径中的非法字符。
在行:1 字符:38
+ ... lude_files){Get-ChildItem -Path C:\Files

感谢是否有人可以提供帮助?

标签: windowspowershell

解决方案


一个简单的方法来做到这一点

ls C:\files | Foreach {
        Move-Item -Path C:\files\$filetype -Destination C:\dest
}

推荐阅读