This script is designed to scan a directory and rename files based on their MIME types. It can be useful for organizing files by type or recovering file extensions.
- Clone the Repository:
git clone https://github.com/imenemedjaoui/file_ext_recover.git
- Navigate to the Directory:
cd your-repository
- Install Dependencies:
pip install -r requirements.txt
- Put the Files in the same Directory:
- Make sure to put the files you want to rename in the same directory as the script.
- Run the Script:
python rename_files.py
- Python 3.x
- python-magic
- python-magic-bin: This is a Windows-compatible version of the
python-magic
library.
- Organizing Files: Use this script when you have a directory containing files with missing extensions and you want to organize them by type.
- Standardizing File Extensions: It's handy when you need to ensure all files have consistent extensions based on their MIME types.
- The script uses the
magic
library to determine file MIME types, so it's essential to have it installed. - If the
mimetypes.guess_extension()
function fails to guess the extension, it defaults to.dat
. You can modify this behavior as needed in the script. - The script is safe to run in any directory, as it will not rename files that already have an extension.
- Imene Medjaoui
- Contact: medjaoui.imene@gmail.com