Download on GitHub This script renames files and folders with "illegal" characters (characters not allowed in Windows file names) by replacing these characters with a hyphen ('-'). This is particularly useful for synchronizing files from macOS to OneDrive or other services that follow Windows naming conventions.
Requirements
- Python 3.x
osmodule (standard library)
Script Overview
The script performs the following operations:
- Walks through a specified directory.
- Identifies files and folders with disallowed characters in their names.
- Renames the identified files and folders by replacing disallowed characters with a hyphen ('-').
- Logs the renaming actions in a text file (
renamed_files.txt).
Disallowed Characters
The following characters are considered illegal in Windows file and folder names and will be replaced:
<>:/\|?*"
Usage
- Set the Directory: Update the
DIRECTORYvariable with the path of the directory you want to process. - Run the Script: Execute the script using Python.
Example
Replace "/path/to/your/directory" with the actual directory path you wish to process.
NOTES
- Ensure that you have write permissions for the directory and the files within it.
- The script appends log information to renamed_files.txt. This file will be created in the current working directory if it does not exist.
- Be cautious when running the script in directories with many files and subdirectories as it may take some time to process.
!! IMPORTANT !!
- I suggest you create a backup of the folder to avoid any problems.
CREDITS
Made by h0ag for Computer Doctor