如何使用批处理脚本删除文件夹名称的前7个字符? [英] How to delete first 7 characters of folder name by using batch script?

查看:94
本文介绍了如何使用批处理脚本删除文件夹名称的前7个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实做了研究,但我不知道,对不起! Google只能帮助我添加字符,而不能删除字符...

I did do research but I could not figure out, sorry! Google can only help me to add characters but not delete characters...

在目录E:\Movies\2011\

有几个文件夹 例如

[0603] Movie_1

[0708] Movie_2

[0811] Movie_3

以此类推.

所以我想运行一个批处理脚本来删除日期标签 即

So I want to run a batch script to remove date tag i.e.

Movie_1

Movie_2

Movie_3

以此类推

我正在使用Windows 8.

I am using windows 8.

推荐答案

RENAMER.CMD

RENAMER.CMD

@echo off
setlocal enableextensions enabledelayedexpansion
for %%i in (*) do (set name=%%i && ren "!name!" "!name:~7!")
endlocal

说明:

setlocal / endlocal 东西只是确保不管您的默认命令行设置如何,脚本都可以正常工作.如果您确保默认情况下启用了命令扩展名和延迟扩展名,或者使用 cmd/e:on/v:on 启动命令提示符,则这些行是可选的.

The setlocal / endlocal stuff just makes sure that the script will work no matter what your default commandline settings are. Those lines are optional if you make sure that command extensions and delayed expansion are enabled by default, or if you start your command prompt using cmd /e:on /v:on.

for 语句是关键.它使用(*)选择目录中的每个文件.如果只想更改带有某些扩展名的文件,则可以使用其他模式,例如(*.avi).然后!name:〜7!从前面减去七个字符. 设置/?列出了您可以执行的其他一些操作.大多数示例使用代替,但是所有字符串操作都可同时使用.

The for statement is the heart of the thing. It selects every file in the directory using (*). If you only want to change files with certain extensions you can use a different pattern such as (*.avi). Then !name:~7! takes seven characters off the front. set /? lists some of the other manipulations you can perform. Most of the examples use % instead of ! but all string manipulations work with both.

已更新为回答评论

Updated to answer comment

您可以在!内执行%替换.替代.

You can perform a % substitution inside a ! substitution.

@echo off
setlocal enableextensions enabledelayedexpansion
set numtrim=7
for %%i in (*) do (set name=%%i && ren "!name!" "!name:~%numtrim%!")
endlocal

这篇关于如何使用批处理脚本删除文件夹名称的前7个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆