' 检查文件是否存在
If Dir(oldFileName) <> "" Then
' 重命名文件
Name oldFileName As newFileName
Else
MsgBox "文件 " & oldFileName & " 不存在。", vbExclamation
End If
Next i
rem 替换 "path_to_your_excel_file.xlsx" 为你的 Excel 文件路径
set "excel_file=path_to_your_excel_file.xlsx"
rem 替换 "path_to_your_image_folder" 为包含图片文件的文件夹路径
set "image_folder=path_to_your_image_folder"
rem 替换 "path_to_your_sorted_image_folder" 为你想要保存排序后图片的文件夹路径
set "sorted_image_folder=path_to_your_sorted_image_folder"
rem 读取 Excel 文件中的姓名和顺序,并逐行处理
for /f "tokens=1,2 delims=," %%a in ('type "%excel_file%" ^| findstr /r /v "^$"') do (
rem 构建旧的和新的文件路径
set "old_file_path=%image_folder%\%%a.jpg"
set "new_file_name=%%b_%%a.jpg"
set "new_file_path=%sorted_image_folder%\!new_file_name!"
rem 如果图片文件存在,将其重命名
if exist "!old_file_path!" (
ren "!old_file_path!" "!new_file_name!"
) else (
echo 图片文件 "!old_file_path!" 不存在。
)
)