写一个bat将当前文件夹下图片和视频文件,将图片和视频文件的的文件名修改为对应文件的创建时间,如果时间重复在后面加上序号,并且每个步骤加上0.1s的延时,同时防止获取不到文件出现异常,最后需要点击确认
时间: 2023-06-25 14:05:23 浏览: 182
@echo off
setlocal enabledelayedexpansion
echo 1. 正在获取文件列表...
ping 127.0.0.1 -n 1 -w 100 > nul
set count=0
for %%a in (*.jpg *.jpeg *.png *.bmp *.gif *.mp4 *.mov *.avi *.wmv) do (
set /a count+=1
set "file[!count!]=%%a"
)
echo 获取到 %count% 个文件
echo 2. 正在重命名文件...
ping 127.0.0.1 -n 1 -w 100 > nul
for /l %%i in (1, 1, %count%) do (
set "cur_file=!file[%%i]!"
set "file_date="
set "file_time="
for /f "usebackq delims=" %%j in (`powershell "(get-item '!cur_file!').creationtime"`) do set "file_date=%%j"
for /f "usebackq delims=" %%j in (`powershell "(get-item '!cur_file!').creationtime.tostring('HHmmss')"`) do set "file_time=%%j"
set "new_file_name=!file_date!_!file_time!%%~xa"
set "index=0"
:loop
set /a index+=1
if exist "!new_file_name!" (
set "new_file_name=!file_date!_!file_time!_!index!%%~xa"
goto loop
)
echo "!cur_file!" --^> "!new_file_name!"
ren "!cur_file!" "!new_file_name!"
ping 127.0.0.1 -n 1 -w 100 > nul
)
echo 3. 执行完毕,请按任意键确认...
pause > nul
阅读全文