【问题标题】:rename multiple files using substring of the filename使用文件名的子字符串重命名多个文件
【发布时间】:2016-03-31 03:15:13
【问题描述】:

我在 Windows 中有 100 个文件,其名称类似于

W-cat_T_1001_s.jpg
W-dog_T_12112_o.jpg
W-rabbit_T_121_w.jpg

例如,我想将所有文件重命名为其子字符串

cat.jpg
dog.jpg 
rabbit.jpg

我的方法是首先在 powerShell 中将 "_T_*" 替换为 "" 类似

DIR| Rename-Item -NewName {$_.Name -replace "_T_*", ""}

这会出错

Rename-Item : Cannot rename because item at 'z' does not exist

我不知道这是否是一种正确的方法,以及使用 PowerShell、批处理文件、java 或简单的“重命名”命令是否合适。

【问题讨论】:

    标签: powershell


    【解决方案1】:
    dir |  Rename-Item -NewName {$_.Name -replace 'W-(.*)_T_.*','$1.jpg'}
    

    【讨论】:

      猜你喜欢
      • 2011-12-27
      • 2018-07-12
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      • 2014-02-13
      相关资源
      最近更新 更多