Powershell:将文件夹和子文件夹中的所有文件移动到单个文件夹中

tac*_*ack 19 powershell

尝试索引和搜索8K文件和2K文件夹中的文件..

是否有一个简单的Powershell脚本可以将文件夹和/或子文件夹中的所有文件移动到一个主文件夹中?

不需要删除空文件夹但会有所帮助.

Don*_*ank 31

第四个例子help -Examples Move-Item接近你所需要的.要将目录下的所有文件移动sourcedest目录,您可以执行以下操作:

Get-ChildItem -Path source -Recurse -File | Move-Item -Destination dest
Run Code Online (Sandbox Code Playgroud)

如果要在之后清除空目录,可以使用类似的命令:

Get-ChildItem -Path source -Recurse -Directory | Remove-Item
Run Code Online (Sandbox Code Playgroud)

  • 我不确定您要做什么。当然,您必须知道目标目录,否则操作将不知道将文件放在何处。 (2认同)