# -*- coding: utf-8 -*-
import os
# 列出当前目录下所有的文件
import numpy
a = "/home/yinhaibo/Downloads/challenge/www.physionet.org/www.physionet.org/physiobank/database/apnea-ecg/"
files = os.listdir('/home/yinhaibo/Downloads/challenge/www.physionet.org/www.physionet.org/physiobank/database/apnea-ecg/')
print('files',files)
for filename in files:
portion = os.path.splitext(filename)
# 如果后缀是.dat
if portion[1] == ".dat":
#print("OOOOO")
# 重新组合文件名和后缀名
#
newname = portion[0] + ".txt"
print(newname)
oldname = a + filename
newname = a + newname
os.rename(oldname, newname)
最后一行必须要用绝对路径文件名名
,或者用相对路径。
参考: https://blog.csdn.net/rosefun96/article/details/78968490