Rename files in a directory by removing non-alphanumeric characters that shouldn't be in a filename.
✓ Published0🌍 Public
LLeeMendelowitz
Last edited Oct 31, 2014
Created on Oct 31, 2014
This example shows a Python script that recursively renames files and directories by replacing whitespace with underscores and stripping non-alphanumeric characters except periods, underscores, and hyphens. It walks the file system using `os.walk` and applies regular-expression substitutions via the `re` module, then moves each item with `shutil.move`. The script operates on user-specified directories or the current working directory, printing each rename action to standard error as it proceeds.
AI-generated description