• HWIKI

    Build. Break. Explain.

    OneDrive Illegal Char Renamer

    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
    • os module (standard library)

    Script Overview

    The script performs the following operations:

    1. Walks through a specified directory.
    2. Identifies files and folders with disallowed characters in their names.
    3. Renames the identified files and folders by replacing disallowed characters with a hyphen ('-').
    4. 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

    1. Set the Directory: Update the DIRECTORY variable with the path of the directory you want to process.
    2. Run the Script: Execute the script using Python.

    Example

    python
    DIRECTORY = "/path/to/your/directory"
    

    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