【问题标题】:how to move bulk move files and then rename them in sequential order?如何移动批量移动文件,然后按顺序重命名它们?
【发布时间】:2017-10-31 11:31:04
【问题描述】:

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

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

我的最终目标是使用 GCI + ForEach-Object 来移动大量文件。但我现在正在使用单个文件进行测试。

这是我的脚本:

$_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"

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

你能帮忙吗?谢谢

【问题讨论】:

  • 启动 stackoverflow.com/questions/42773089/… 然后重命名每个循环中的每个项目
  • @matt7 我可以在 1 个命令中移动和重命名它们。只是不知道如何在新文件上使用自动递增代码。

标签: powershell


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    相关资源
    最近更新 更多