版权声明:@liaogaoyong https://blog.csdn.net/qq_42455710/article/details/88872675
#获取指定磁盘下的txt文件列表#1
def getTxtFiledir(FindPath):
suffix='.txt'#文件后缀
FileList = []
FileNames = os.listdir(FindPath)
for filename in FileNames:
name, suf = os.path.splitext(filename) # =>文件名,文件后缀
if suf == suffix:
FileList.append(os.path.join(FindPath, filename)) # =>吧一串字符串组合成路径
return FileList
#删除指定磁盘下的txt文件
def deleteTxtFile(FindPath):
fileLists = getTxtFiledir(FindPath)
for file in fileLists:
print(file)
os.remove(file)