Skip to content

Instantly share code, notes, and snippets.

@jasonren0403
Created October 25, 2021 01:25
Show Gist options
  • Save jasonren0403/41c80e366237d63f6b7745a40184f8a7 to your computer and use it in GitHub Desktop.
Save jasonren0403/41c80e366237d63f6b7745a40184f8a7 to your computer and use it in GitHub Desktop.
batch renaming files
import os
path=os.path.dirname(os.path.abspath(__file__))
old_list=os.listdir(path)
n=0
#print(old_list)
for file in old_list:
old_name=file
if '.html' not in old_name or not '_c#' in old_name: # if old_name=='rename.py' or not '_cs' in old_name
continue
old_path=os.path.join(path,old_name)
if os.path.isdir(old_path):
continue
new_name=old_name.replace('_c#','_cs') # new_name=old_name.replace('_cs','_c#')
new_path=os.path.join(path,new_name)
os.rename(old_path,new_path)
n+=1
print(old_path+"====>"+new_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment