常用 Windows 批处理脚本
windows 批处理示例
常用 Windows 批处理脚本
批量重命名文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@echo off
@chcp 65001 2>nul 1>nul
setlocal enabledelayedexpansion
if "%~1" equ "" (
call :rename "txt" "md"
) else (
call :rename "tmp" "md"
)
exit /b
:rename
FOR /r %%i IN (*) DO (
rem echo %%i,%%~xi
if "%%~xi" equ ".%~1" (
echo %%~fi --^> %%~ni.%~2
rename "%%~fi" "%%~ni.%~2"
)
)
exit /b
获取字符串长度
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@echo off
setlocal ENABLEDELAYEDEXPANSION
chcp 65001 1>nul 2>nul
set /p str=请输入任意长度字符串:
if not defined str goto :eof
echo 您输入了:%str%
call :getStrLen str
goto :eof
:getStrLen
set x=0
set tmpStr=!%1!
:label
set /a x+=1
set tmpStr=%tmpStr:~0,-1%
if defined tmpStr goto :label
echo 字符串长度:%x%
goto :eof
:eof
本文由作者按照 CC BY 4.0 进行授权