Python batch delete empty files in the folder subfolders

A folder for example, under many sub-folders, I need to get is a sub-folder of pictures, but now subfolders are not only pictures, but also mixed with empty folder (when using OpenImages toolbox, in accordance with retrieve the image file is downloaded with the label, but the classification procedures may be some small bug and retrieval, as it will be more out of a label folder)

import os
dirpath = 'yourpath/OIDv4_ToolKit/OID/Dataset_nl/train'
def delfiles(dirpath):
    for root, dirs, files in os.walk(dirpath):
        if dirs == files:
            os.rmdir(root)    
delfiles(dirpath)

The logic is simple, that is, when the folders and files are empty, indicating that the label into the folder, and then delete the label folder.

Guess you like

Origin www.cnblogs.com/tay007/p/11322412.html