Powered by Python and Excel
这是一个基于Python的简单脚本,用于批量重命名学生照片文件。该脚本根据Excel表格中的学号和身份证号对应关系,将照片文件名从学号格式重命名为身份证号格式。
- 📁 批量处理:一键批量重命名大量照片文件
- 📊 Excel支持:从Excel文件读取学号-身份证号对应关系
- 🔄 智能匹配:自动匹配并重命名文件
- 📝 详细日志:提供完整的处理日志和错误报告
- 🛡️ 安全可靠:包含文件存在性检查,避免误操作
- ⚡ 高效快速:处理速度快,适合大批量文件操作
- Python 3.8+
- pandas库
- openpyxl库(用于读取.xlsx文件)
pip install pandas openpyxl-
Excel文件:包含两列数据
- 第一列:学号
- 第二列:身份证号
- 文件格式:
.xlsx或.xls
-
照片文件夹:
- 包含需要重命名的照片文件
- 照片文件名格式:
{学号}.jpg - 支持其他图片格式(需修改脚本中的文件扩展名)
git clone https://github.com/yourusername/photo-rename-tool.git
cd photo-rename-tool修改脚本中的以下路径变量:
# Excel文件路径
file_path = r'你的Excel文件路径.xlsx'
# 照片文件夹路径
photo_folder = r'你的照片文件夹路径'python rename_photos.py脚本将输出处理日志:
- ✅ 成功重命名的文件
⚠️ 未找到的文件- 📊 处理统计信息
photo-rename-tool/
├── rename_photos.py # 主脚本文件
├── README.md # 说明文档
├── LICENSE # 许可证文件
├── target/ # 示例文件
│ └── photos # 照片文件夹示例
└── test.xlsx # 测试文件
| 学号 | 身份证号 |
|---|---|
| 20230001 | 110101199001011234 |
| 20230002 | 110101199002021235 |
| 20230003 | 110101199003031236 |
| ... | ... |
- 备份数据:建议在运行前备份原始照片文件
- 文件扩展名:默认处理
.jpg格式,如需其他格式请修改脚本 - 路径设置:确保所有路径正确且文件存在
- 权限检查:确保有文件读写权限
- 编码问题:确保Excel文件编码正确
# 修改文件扩展名
old_file_name = f"{student_id}.png" # 改为.png或其他格式
new_file_name = f"{id_number}.png"# 如果Excel列顺序不同,可以调整列索引
student_ids = df.iloc[:, 1].tolist() # 第二列作为学号
id_numbers = df.iloc[:, 2].tolist() # 第三列作为身份证号- 使用pandas批量读取Excel数据,提高效率
- 内存占用低,适合处理大量文件
- 支持增量处理,可中断后继续
A: 检查照片文件名是否与Excel中的学号完全一致,包括大小写和格式。
A: 修改脚本中的文件扩展名,如.png、.jpeg等。
A: 确保安装了openpyxl库,且文件格式正确。
A: 确保有文件读写权限,或尝试以管理员身份运行。
欢迎提交Issue和Pull Request来改进这个项目!
- Fork 本仓库
- 创建您的特性分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启一个Pull Request
本项目采用MIT许可证。详见 LICENSE 文件。
感谢所有为本项目做出贡献的人!
如有问题或建议,请在 GitHub Issues 中提出。
提示:使用前请务必备份重要数据!
Powered by Python and Excel
This is a simple Python script for batch renaming student photo files. The script renames photo filenames from student ID format to ID card number format based on the mapping relationship in an Excel spreadsheet.
- 📁 Batch Processing: Batch rename large numbers of photo files with one click
- 📊 Excel Support: Read student ID - ID card number mapping from Excel files
- 🔄 Smart Matching: Automatically match and rename files
- 📝 Detailed Logging: Provide complete processing logs and error reports
- 🛡️ Safe & Reliable: Includes file existence checks to prevent misoperations
- ⚡ Efficient & Fast: Fast processing speed, suitable for large-scale file operations
- Python 3.8+
- pandas library
- openpyxl library (for reading .xlsx files)
pip install pandas openpyxl-
Excel File: Contains two columns of data
- First column: Student ID
- Second column: ID card number
- File format:
.xlsxor.xls
-
Photo Folder:
- Contains photo files that need to be renamed
- Photo filename format:
{student_id}.jpg - Supports other image formats (requires modifying file extension in script)
git clone https://github.com/yourusername/photo-rename-tool.git
cd photo-rename-toolModify the following path variables in the script:
# Excel file path
file_path = r'your_excel_file_path.xlsx'
# Photo folder path
photo_folder = r'your_photo_folder_path'python rename_photos.pyThe script will output processing logs:
- ✅ Successfully renamed files
⚠️ Files not found- 📊 Processing statistics
photo-rename-tool/
├── rename_photos.py # Main script file
├── README.md # Documentation
├── LICENSE # License file
├── target/ # Example files
│ └── photos # Photo folder example
└── test.xlsx # Test file
| Student ID | ID Card Number |
|---|---|
| 20230001 | 110101199001011234 |
| 20230002 | 110101199002021235 |
| 20230003 | 110101199003031236 |
| ... | ... |
- Backup Data: It is recommended to backup original photo files before running
- File Extension: Default processes
.jpgformat. To use other formats, please modify the script - Path Settings: Ensure all paths are correct and files exist
- Permission Check: Ensure you have file read/write permissions
- Encoding Issues: Ensure Excel file encoding is correct
# Modify file extension
old_file_name = f"{student_id}.png" # Change to .png or other formats
new_file_name = f"{id_number}.png"# If Excel column order is different, adjust column indices
student_ids = df.iloc[:, 1].tolist() # Second column as student ID
id_numbers = df.iloc[:, 2].tolist() # Third column as ID card number- Uses pandas for batch Excel data reading, improving efficiency
- Low memory usage, suitable for processing large numbers of files
- Supports incremental processing, can resume after interruption
A: Check if photo filenames exactly match student IDs in Excel, including case and format.
A: Modify the file extension in the script, such as .png, .jpeg, etc.
A: Ensure openpyxl library is installed and file format is correct.
A: Ensure you have file read/write permissions, or try running as administrator.
Welcome to submit Issues and Pull Requests to improve this project!
- Fork this repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
Thanks to all who have contributed to this project!
If you have questions or suggestions, please submit them in GitHub Issues.
Tip: Always backup important data before use!