Skip to content

Instantly share code, notes, and snippets.

@CheezusChrust
Created January 12, 2022 00:42
Show Gist options
  • Save CheezusChrust/ca5602d030b9714b4ac2ad664165f7cd to your computer and use it in GitHub Desktop.
Save CheezusChrust/ca5602d030b9714b4ac2ad664165f7cd to your computer and use it in GitHub Desktop.
Changes the file extension of all files in the directory of this file. Don't know who else may need this but have it anyways.
import os
import time
extensionFrom = ".txt"
extensionTo = ".qc"
count = 0
for f in os.listdir():
if f.endswith(extensionFrom):
count += 1
os.rename(f, f.replace(extensionFrom, extensionTo))
print(f + " -> " + f.replace(extensionFrom, extensionTo))
if count == 0:
print("No files found with extension " + extensionFrom)
else:
print("\nRenamed " + str(count) + " file extensions.")
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment