[python]如何刪除目錄下指定格式的檔案

VictorLeeLk發表於2017-09-03
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 03 22:01:25 2017

@author: Administrator
"""


#!/usr/bin/python
# -*- coding: utf-8 -*-

import os

def del_files(path):
    for root , dirs, files in os.walk(path):
        for name in files:
            if name.endswith(".jpg"):
                os.remove(os.path.join(root,name))         
    print ("Delete File: " + os.path.join(root, name))

# test
if __name__ == "__main__":
    path = r'E:\VedioClassfication\five-video-classification-methods-master\five-video-classification-methods-master\data\train'
    del_files(path)

相關文章