您的位置:首页 > 编程语言 > Python开发

Python-修改文件夹下所有文件的名字

2017-05-18 13:42 337 查看
import os

def renameFile():
fileList = os.listdir(r"C:\Users\dell\Desktop\Udacity\prank\prank")
print(fileList)
# get current work path
currentpath = os.getcwd()
print("Current is "+currentpath)
# change current work path
os.chdir(r"C:\Users\dell\Desktop\Udacity\prank\prank")
for fileName in fileList:
print("Original is " + fileName)
# delete 0123456789 in file name
os.rename(fileName, fileName.translate(None, "0123456789"))
print("Changed is " + fileName.translate(None, "0123456789"))
os.chdir(currentpath)
renameFile()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息