代码之家  ›  专栏  ›  技术社区  ›  mrjayviper

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

  •  0
  • mrjayviper  · 技术社区  · 7 年前

    目标文件夹路径是动态的,所以在测试中我使用了一个变量

    我的最终目标是使用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"
    

    但是我不知道如何用它来引入自动递增代码。

    你能帮忙吗?谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   Krisz    7 年前

    尝试分别计算格式字符串:

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