python修改文件名(去数字)

import os

#get filenames from a certain directory

filenames = os.listdir(r"C:\Users\Bennett\Desktop\LearnPy")   

##cwd = os.getcwd()     get current working directory

##print(cwd)

os.chdir(r"C:\Users\Bennett\Desktop\LearnPy")   ##change working directory

for filename in filenames:

     os.rename(filename,filename.translate(None,'0123456789'))   #translate!!


'translate' documentation

你可能感兴趣的:(python修改文件名(去数字))