Hunter的大杂烩

September 15, 2020

dos批处理脚本修改文件名

Filed under: 技术话题 — hunter @ 1:48 am

参考:

https://blog.csdn.net/A_BlackMoon/article/details/79998515

https://blog.csdn.net/txl199106/article/details/79266785

https://zhidao.baidu.com/question/233580687.html

批处理知识:

1. 使用set local enabledelayedexpansion之后,局部变量要使用 !var!方式引用

2. %%~i 表示完整路径的文件名, %%~nxi表示不带路径的文件名

3. 使用 set nfn=%nfn:你要排除的字符串=% 来替换掉想要去除的字符或字符串

完整批处理脚本如下:


@echo off
@setlocal enabledelayedexpansion

@for /f "delims=" %%i in ('dir /b *.mp4') do (
@call :renameFiles "%%~i"
@pause
)

:renameFiles
set nfn=%~nx1
set nfn=%nfn:!=%
set nfn=%nfn:+=%
@rem set nfn=%nfn: =%
@echo %nfn%

ren "%~1" "%nfn%"

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress