批量去除文件名中的某些字符串

作者:何先生
链接:https://www.zhihu.com/question/29446913/answer/218671011
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

1、可以用软件实现,比如拖把更名器,菲菲更名宝贝。

个人之前就用菲菲更名宝贝,但每次都需要启动软件,贴入文件夹路径,载入文件夹内文件,再选择功能,再输入替换前后文字,有点麻烦。

2、后来改用批处理了,发现速度更快,所以偏爱上了,一直沿用至今。

批处理代码如下:

@echo off

set /p str1= 请输入要替换的文件(文件夹)名字符串(可替换空格):

set /p str2= 请输入替换后的文件(文件夹)名字符串(去除则直接回车):

echo.

echo 正在修改文件(夹)名中,请稍候……

for /f "delims=" %%a in ('dir /s /b ^|sort /+65535') do (

if "%%~nxa" neq "%~nx0" (

set "file=%%a"

set "name=%%~na"

set "extension=%%~xa"

call set "name=%%name:%str1%=%str2%%%"

setlocal enabledelayedexpansion

ren "!file!" "!name!!extension!" 2>nul

endlocal

)

)

exit


在电脑上新建文本文件:

<img src="https://pic1.zhimg.com/50/v2-760a67ff303061dd02b08181753448a8_hd.jpg" data-rawwidth="234" data-rawheight="143" class="content_image" width="234">

将以上代码复制到文本里面,保存,更改文件名为(文件扩展名也改):

<img src="https://pic1.zhimg.com/50/v2-4e651392b2536467b14a1c9f21070e07_hd.jpg" data-rawwidth="286" data-rawheight="26" class="content_image" width="286">

PS: .bat是更改后的文件扩展名

将这个批处理文件放到你要批量更改文件的文件夹内

<img src="https://pic2.zhimg.com/50/v2-e0044732bd7339c9bc7e5ad2aadfd147_hd.jpg" data-rawwidth="458" data-rawheight="225" class="origin_image zh-lightbox-thumb" width="458" data-original="https://pic2.zhimg.com/v2-e0044732bd7339c9bc7e5ad2aadfd147_r.jpg">

点击运行,输入更改前后的字符比如“+8.23”:

<img src="https://pic1.zhimg.com/50/v2-ba596cf1cb59b468e17320716398b474_hd.jpg" data-rawwidth="475" data-rawheight="76" class="origin_image zh-lightbox-thumb" width="475" data-original="https://pic1.zhimg.com/v2-ba596cf1cb59b468e17320716398b474_r.jpg">

第二行直接回车后,就完成了,(“+8.23”被批量删除了):

<img src="https://pic1.zhimg.com/50/v2-b960b34dd35d4245775006ea4cf7d51c_hd.jpg" data-rawwidth="414" data-rawheight="215" class="content_image" width="414">

速度比用工具软件更快一些:少了启动软件,复制和贴入文件夹路径,加载文件夹内文件和选择选项的时间。

这个也可用来替换字符,在第二行时输入替换后的字符如“+8.24”:

<img src="https://pic3.zhimg.com/50/v2-f76cfd0fd7d3b6c42d77aea62ee1740d_hd.jpg" data-rawwidth="511" data-rawheight="76" class="origin_image zh-lightbox-thumb" width="511" data-original="https://pic3.zhimg.com/v2-f76cfd0fd7d3b6c42d77aea62ee1740d_r.jpg">

回车,就完成了替换了(+8.23批量替换成+8.24了):

<img src="https://pic1.zhimg.com/50/v2-3d883223defa2d1aa93519e4c8965150_hd.jpg" data-rawwidth="404" data-rawheight="206" class="content_image" width="404">

也可以同步修改所有子文件夹名称,以及所有子文件夹内的文件名。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值