Python之文件处理-递归删除特定文件
Python之文件处理-递归删除特定文件
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
def delete_particular_file(top):
for root, dirs, files in os.walk(top, topdown=False):
for file_name in files:
if file_name.split('.')[-1] == 'ipynb':
delete_file_name = os.path.join(root, file_name)
os.remove(delete_file_name)
print(f'{delete_file_name} done...')
# for name in dirs:
# os.rmdir(os.path.join(root, name))
if __name__ == '__main__':
top = '/Users/mac/Desktop'
delete_particular_file(top)