Created
October 25, 2021 01:25
-
-
Save jasonren0403/41c80e366237d63f6b7745a40184f8a7 to your computer and use it in GitHub Desktop.
batch renaming files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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