加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

使用Windows批处理脚本重命名目录中的所有文件

发布时间:2020-12-13 20:10:10 所属栏目:Windows 来源:网络整理
导读:我将如何编写一个批次或cmd文件来重命名目录中的所有文件?我正在使用 Windows. 改变这个: 750_MOT_Forgiving_120x90.jpg751_MOT_Persecution_1_120x90.jpg752_MOT_Persecution_2_120x90.jpg753_MOT_Hatred_120x90.jpg754_MOT_Suffering_120x90.jpg755_MOT_
我将如何编写一个批次或cmd文件来重命名目录中的所有文件?我正在使用 Windows.

改变这个:

750_MOT_Forgiving_120x90.jpg
751_MOT_Persecution_1_120x90.jpg
752_MOT_Persecution_2_120x90.jpg
753_MOT_Hatred_120x90.jpg
754_MOT_Suffering_120x90.jpg
755_MOT_Freedom_of_Religion_120x90.jpg
756_MOT_Layla_Testimony_1_120x90.jpg
757_MOT_Layla_Testimony_2_120x90.jpg

为此:

750_MOT_Forgiving_67x100.jpg
751_MOT_Persecution_1_67x100.jpg
752_MOT_Persecution_2_67x100.jpg
753_MOT_Hatred_67x100.jpg
754_MOT_Suffering_67x100.jpg
755_MOT_Freedom_of_Religion_67x100.jpg
756_MOT_Layla_Testimony_1_67x100.jpg
757_MOT_Layla_Testimony_2_67x100.jpg
FOR语句循环使用名称(键入FOR /?以获取帮助),并进行字符串搜索和替换(输入SET /?作为帮助).
@echo off
setlocal enableDelayedExpansion
for %%F in (*120x90.jpg) do (
  set "name=%%F"
  ren "!name!" "!name:120x90=67x100!"
)

更新 – 2012-11-07

我调查了RENAME命令如何处理通配符:How does the Windows RENAME command interpret wildcards?

事实证明,使用RENAME命令可以很容易地解决这个特殊问题,而不需要批处理脚本.

ren *_120x90.jpg *_67x100.*

_之后的字符数不重要.如果120×90成为x或xxxxxxxxxx,重命名仍然可以正常工作.这个问题的重要方面是最后一个_和之间的整个文本.被替换

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读