批量去除一个文件夹目录下的文件后缀的脚本

'''
@Description:
@Author: Sp4ce
@Github: https://github.com/NS-Sp4ce
@LastEditors: Sp4ce
@Date: 2019-03-23 23:37:27
@LastEditTime: 2019-03-23 23:58:22
'''

import os
def getFileExt(path):
''' 获取指定目录下的所有指定后缀的文件名 '''

f_list = os.listdir(path)
for file in f_list:
fileName=file
#print(fileName)
file_ext=os.path.splitext(file)[-1]
#print(file_ext)
#print(os.path.splitext(file)[0])
if file_ext == '.下载': #指定后缀
reNameFileExt(fileName)

def reNameFileExt(fileName):
''' 去除后缀'''
newFileName = os.path.splitext(fileName)[0]
oldFileName=path +'\\' +fileName
changeFileName= path +'\\' +newFileName
os.rename(oldFileName,changeFileName)

if __name__ == '__main__':

path = ''
getFileExt(path)