批量刪除當前目錄下後綴爲.txt的文件python
a = os.getcwd() b = os.listdir() for i in b: # 分割路徑,返回路徑名和文件擴展名的元組 ext = os.path.splitext(i) if ext[1] == '.txt': file = os.path.join(a, i) os.remove(file)