This repository contains a Python script that rename files based on data from a CSV or Excel file. The script reads the old and new file names from a CSV file and renames files in a specified folder accordingly.
This project was created due to an assignment to rename over 5,000 files for import purposes. The task involved exporting student data as a CSV and concatenating student IDs to the old document names in order to generate new document names. The script automates this renaming process by reading the old and new file names from a CSV file and renaming the documents accordingly.
- CSV Input: The script loads a CSV file that contains two columns:
Current Document Name
andNew Document Name
. - File Renaming: It renames the files in a specified folder based on the provided names.
- Bulk Renaming: Designed to handle a large volume of files (5,000+).
- Error Handling: The script checks if files exist before renaming and handles any renaming errors.
- Logs: Prints out information on whether each file was successfully renamed or if any errors occurred.
- Python 3.x
- Pandas (
pip install pandas
)
-
Prepare the CSV File:
- Create a CSV file with two columns:
Current Document Name
andNew Document Name
. - Each row should contain the old file name and the corresponding new file name, typically by concatenating student IDs to the original file names.
- Create a CSV file with two columns:
-
Specify Folder Path:
- Update the script to point to the folder where your files are stored:
folder = r'C:\path\to\your\folder'
- Update the script to point to the folder where your files are stored:
-
Run the Script:
- Ensure the CSV file path is correctly specified in the script:
df = pd.read_csv(r'C:\path\to\your\csvfile.csv')
- Run the Python script:
python rename_files.py
- Ensure the CSV file path is correctly specified in the script:
-
Output:
- The script will print the renaming status of each file. It will notify you if a file is not found or if an error occurs during the renaming process.