Skip to content

Instantly share code, notes, and snippets.

@dsbilling
Created December 15, 2021 14:09
Show Gist options
  • Select an option

  • Save dsbilling/af3b48e1fdb619b3a4f012ceaeeba76b to your computer and use it in GitHub Desktop.

Select an option

Save dsbilling/af3b48e1fdb619b3a4f012ceaeeba76b to your computer and use it in GitHub Desktop.
Rename files in current directory and sub-directories
import os
def process_directory(root):
for root, dirs, files in os.walk(root):
for name in files:
if name.endswith(".new"):
print("Renamed -> ", name)
os.rename(os.path.join(root, name), os.path.join(root, name.replace(".new", "")))
process_directory(os.path.dirname(os.path.realpath(__file__)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment