当前目录修改文件名1开始递增
@echo off setlocal enabledelayedexpansion set "counter=1" for %%F in (*.mp4) do ( ren "%%F" "!counter!.mp4" set /a counter+=1 ) echo successes! exit
当前目录全有子目录的视频文件名1开始递增
@echo off echo Renaming mp4 files in subfolders setlocal enabledelayedexpansion set count=1 for /d %%a in (*) do ( pushd "%%a" for %%b in (*.mp4) do ( ren "%%b" "!count!.mp4" set /a count+=1 ) set count=1 popd ) set count=1 for /d %%a in (*) do ( pushd "%%a" for %%b in (*.mp4) do ( ren "%%b" "!count!.mp4" set /a count+=1 ) set count=1 popd )
批处理实现 根目录
@echo off setlocal enabledelayedexpansion set count=1 set sourceFile= for %%i in (*.mp4) do ( if not defined sourceFile ( set sourceFile=%%i ) ) if not defined sourceFile ( echo 根目录下未找到视频文件 pause exit ) copy "%sourceFile%" "1.mp4" copy "%sourceFile%" "2.mp4" copy "%sourceFile%" "3.mp4" del "%sourceFile%" echo 复制完成并删除源文件
判断当前目录下的所有子文件夹里面的视频 是否有4个mp4格式文件 不是的话就输出显示
@echo off setlocal enabledelayedexpansion :: 遍历当前目录下的所有子文件夹 for /d %%d in (*) do ( if exist "%%d" ( set "mp4Count=0" :: 遍历子文件夹中的所有 mp4 文件 for %%f in ("%%d\*.mp4") do ( set /a mp4Count+=1 ) :: 检查 mp4 文件数量 if !mp4Count! neq 4 ( echo 文件夹 "%%d" 的视频文件数≠ 4,实际 !mp4Count!. ) ) ) pause