REM 检查是否拖拽了文件到脚本上 if "%~1"=="" ( echo Usage: %0 ^<input_file1^> [^<input_file2^> ...] exit /b 1 )
REM 获取批处理文件所在的目录 set "script_dir=%~dp0"
:process_files REM 如果有文件待处理则继续,否则退出脚本 if "%~1"=="" ( exit /b 0 )
REM 获取当前日期和时间,并去除空格 set year=%date:~0,4% set month=%date:~5,2% set day=%date:~8,2% set hour=%time:~0,2% if "!hour:~0,1!"==" " set "hour=0!hour:~1,1!" set minute=%time:~3,2% set second=%time:~6,2% set datetime=!year!-!month!-!day!-!hour!-!minute!-!second!
REM 获取第一个待处理的文件 set "input_file=%~1"
REM 使用当前时间生成文件名 set "output_file=%datetime%"
REM 移除文件名中不合法的字符 set "output_file=%output_file:"=%" REM 移除双引号 set "output_file=%output_file:&=and%" REM 替换 & 符号为 "and"
REM 检查输出文件是否已存在,如果存在则增加后缀 if exist "%script_dir%!output_file!.mov" ( set /a count=1 :loop if exist "%script_dir%!output_file%_!count!.mov" ( set /a count+=1 goto :loop ) set "output_file=!output_file!_!count!" ) else ( REM 添加文件扩展名 set "output_file=%output_file%.mov" )