Skip to content

这是一个基于Python的简单脚本,用于批量重命名有规则化命名的文件(如学生证件照统一命名为身份证号码等)。该脚本根据Excel表格中的学号和身份证号对应关系,将照片文件名从学号格式重命名为身份证号格式。 This is a simple Python script for batch renaming student photo files.

License

Notifications You must be signed in to change notification settings

cmijohnson/RuleBasedFileRenamer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RuleBasedFileRenamer规则文件批量重命名工具

Powered by Python and Excel

Python Version License Pandas Openpyxl

这是一个基于Python的简单脚本,用于批量重命名学生照片文件。该脚本根据Excel表格中的学号和身份证号对应关系,将照片文件名从学号格式重命名为身份证号格式。

✨ 功能特性

  • 📁 批量处理:一键批量重命名大量照片文件
  • 📊 Excel支持:从Excel文件读取学号-身份证号对应关系
  • 🔄 智能匹配:自动匹配并重命名文件
  • 📝 详细日志:提供完整的处理日志和错误报告
  • 🛡️ 安全可靠:包含文件存在性检查,避免误操作
  • 高效快速:处理速度快,适合大批量文件操作

📋 使用前提

环境要求

  • Python 3.8+
  • pandas库
  • openpyxl库(用于读取.xlsx文件)

安装依赖

pip install pandas openpyxl

文件准备

  1. Excel文件:包含两列数据

    • 第一列:学号
    • 第二列:身份证号
    • 文件格式:.xlsx.xls
  2. 照片文件夹

    • 包含需要重命名的照片文件
    • 照片文件名格式:{学号}.jpg
    • 支持其他图片格式(需修改脚本中的文件扩展名)

🚀 快速开始

1. 克隆仓库

git clone https://github.com/yourusername/photo-rename-tool.git
cd photo-rename-tool

2. 配置脚本参数

修改脚本中的以下路径变量:

# Excel文件路径
file_path = r'你的Excel文件路径.xlsx'

# 照片文件夹路径
photo_folder = r'你的照片文件夹路径'

3. 运行脚本

python rename_photos.py

4. 查看结果

脚本将输出处理日志:

  • ✅ 成功重命名的文件
  • ⚠️ 未找到的文件
  • 📊 处理统计信息

📁 项目结构

photo-rename-tool/
├── rename_photos.py          # 主脚本文件
├── README.md                 # 说明文档
├── LICENSE                   # 许可证文件
├── target/                 # 示例文件
│   └── photos              # 照片文件夹示例
└── test.xlsx                 # 测试文件

📊 Excel文件格式要求

学号 身份证号
20230001 110101199001011234
20230002 110101199002021235
20230003 110101199003031236
... ...

⚠️ 注意事项

  1. 备份数据:建议在运行前备份原始照片文件
  2. 文件扩展名:默认处理.jpg格式,如需其他格式请修改脚本
  3. 路径设置:确保所有路径正确且文件存在
  4. 权限检查:确保有文件读写权限
  5. 编码问题:确保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数据,提高效率
  • 内存占用低,适合处理大量文件
  • 支持增量处理,可中断后继续

🐛 常见问题

Q: 文件找不到怎么办?

A: 检查照片文件名是否与Excel中的学号完全一致,包括大小写和格式。

Q: 如何处理其他格式的照片?

A: 修改脚本中的文件扩展名,如.png.jpeg等。

Q: Excel文件读取失败?

A: 确保安装了openpyxl库,且文件格式正确。

Q: 权限被拒绝?

A: 确保有文件读写权限,或尝试以管理员身份运行。

🤝 贡献指南

欢迎提交Issue和Pull Request来改进这个项目!

  1. Fork 本仓库
  2. 创建您的特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交您的更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启一个Pull Request

📄 许可证

本项目采用MIT许可证。详见 LICENSE 文件。

👥 贡献者

感谢所有为本项目做出贡献的人!

📞 支持

如有问题或建议,请在 GitHub Issues 中提出。


提示:使用前请务必备份重要数据!

RuleBasedFileRenamer - Rule-Based File Batch Renaming Tool

Powered by Python and Excel

Python Version License Pandas Openpyxl

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.

✨ Features

  • 📁 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

📋 Prerequisites

Environment Requirements

  • Python 3.8+
  • pandas library
  • openpyxl library (for reading .xlsx files)

Install Dependencies

pip install pandas openpyxl

File Preparation

  1. Excel File: Contains two columns of data

    • First column: Student ID
    • Second column: ID card number
    • File format: .xlsx or .xls
  2. 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)

🚀 Quick Start

1. Clone Repository

git clone https://github.com/yourusername/photo-rename-tool.git
cd photo-rename-tool

2. Configure Script Parameters

Modify 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'

3. Run Script

python rename_photos.py

4. View Results

The script will output processing logs:

  • ✅ Successfully renamed files
  • ⚠️ Files not found
  • 📊 Processing statistics

📁 Project Structure

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

📊 Excel File Format Requirements

Student ID ID Card Number
20230001 110101199001011234
20230002 110101199002021235
20230003 110101199003031236
... ...

⚠️ Important Notes

  1. Backup Data: It is recommended to backup original photo files before running
  2. File Extension: Default processes .jpg format. To use other formats, please modify the script
  3. Path Settings: Ensure all paths are correct and files exist
  4. Permission Check: Ensure you have file read/write permissions
  5. Encoding Issues: Ensure Excel file encoding is correct

🔧 Custom Configuration

Modify File Extension

# Modify file extension
old_file_name = f"{student_id}.png"  # Change to .png or other formats
new_file_name = f"{id_number}.png"

Modify Column Index

# 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

📈 Performance Optimization

  • 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

🐛 Frequently Asked Questions

Q: What if files cannot be found?

A: Check if photo filenames exactly match student IDs in Excel, including case and format.

Q: How to handle other photo formats?

A: Modify the file extension in the script, such as .png, .jpeg, etc.

Q: Excel file reading fails?

A: Ensure openpyxl library is installed and file format is correct.

Q: Permission denied?

A: Ensure you have file read/write permissions, or try running as administrator.

🤝 Contribution Guidelines

Welcome to submit Issues and Pull Requests to improve this project!

  1. Fork this repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

👥 Contributors

Thanks to all who have contributed to this project!

📞 Support

If you have questions or suggestions, please submit them in GitHub Issues.


Tip: Always backup important data before use!

About

这是一个基于Python的简单脚本,用于批量重命名有规则化命名的文件(如学生证件照统一命名为身份证号码等)。该脚本根据Excel表格中的学号和身份证号对应关系,将照片文件名从学号格式重命名为身份证号格式。 This is a simple Python script for batch renaming student photo files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages