Skip to content

Instantly share code, notes, and snippets.

@kharloss
Forked from igniteflow/rename.py
Created January 22, 2018 19:53
Show Gist options
  • Save kharloss/bf4a4522f46a3fb71e405d4554ba92e3 to your computer and use it in GitHub Desktop.
Save kharloss/bf4a4522f46a3fb71e405d4554ba92e3 to your computer and use it in GitHub Desktop.
Python script to rename files in directory, transforming spaces to hyphens and the chars to lowercase
import os
"""
Renames the filenames within the same directory to be Unix friendly
(1) Changes spaces to hyphens
(2) Makes lowercase (not a Unix requirement, just looks better ;)
Usage:
python rename.py
"""
path = os.getcwd()
filenames = os.listdir(path)
for filename in filenames:
os.rename(filename, filename.replace(" ", "-").lower())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment