Python batch checks whether the files in the folder meet the requirements

Table of contents

Problem Description:

problem solved:


Problem Description:

Recently, I have manually sorted out some documents. The requirement is that each folder is named after an ID, and each folder stores three contents (as shown in the figure below). How to check in batches whether the three contents of each folder exist? If it does not exist, please output the actual storage content in the current folder directory.

 

 

problem solved:

Note : If it is a mac system, there may be a '.DS_Store' file, you need to use the program marked as mac below to run the command. If it is windows, both commands are fine.

import os
from pdb import set_trace as stop
def file_name(file_dir):
    for root,dirs,files in os.walk(file_dir):
        # print('root:\n',root)
        # print('dirs:\n',dirs)
        # print('files:\n',files)
        # stop()
        # if files==['copyright.pdf', 'source.zip', 'submission.pdf']: # windows
        if len(files)==3 and 'copyright.pdf' in files and 'source.zip' in files and 'submission.pdf' in files: # mac
            continue
        else:
            print('\n该路径下有文件名错误或者缺少文件',root,files) 
if __name__=='__main__':
    file_name('./')

Guess you like

Origin blog.csdn.net/weixin_41862755/article/details/132124880