Powershell 如何移动大容量移动文件,然后按顺序重命名它们?

Powershell 如何移动大容量移动文件,然后按顺序重命名它们?,powershell,Powershell,为了测试,我尝试将c:\Users\myuser\Downloads\test.txt移动到c:\Users\myuser\Documents\mynewname0001.txt 目标文件夹路径是动态的,因此对于我的测试,我使用了一个变量 我的最终目标是使用GCI+ForEach对象移动大量文件。但我现在只测试一个文件 这是我的剧本: $_test = "c:\Users\myuser\Documents" $_i = 1 Move-Item -Path "$($_test)\test.txt

为了测试,我尝试将c:\Users\myuser\Downloads\test.txt移动到c:\Users\myuser\Documents\mynewname0001.txt

目标文件夹路径是动态的,因此对于我的测试,我使用了一个变量

我的最终目标是使用GCI+ForEach对象移动大量文件。但我现在只测试一个文件

这是我的剧本:

$_test = "c:\Users\myuser\Documents"
$_i = 1

Move-Item -Path "$($_test)\test.txt" -Destination "($($_test)\temp\'newname{0:D4}' -f $_i++)"
这就是我得到的错误

Move-Item : Cannot find drive. A drive with the name '(c' does not exist.
如果我不使用以下命令对文件进行排序,我可以移动这些文件:

Move-Item -Path "$($_test)\test.txt" -Destination "$($_test)\temp\newname.txt"
但我不知道如何使用它引入自动递增代码


你能帮忙吗?谢谢

请尝试单独评估格式字符串:

Move-Item -Path "$($_test)\test.txt" -Destination "$_test\a\$('newname{0:D4}' -f $_i++)"

若要开始,请为每个项目重命名a中的每个项目loop@matt7我可以在1个命令中移动和重命名它们。只是不知道如何在新文件上使用自动递增代码。