How to check to see if a folder contains files using python 3

前端 未结 10 1975
暖寄归人
暖寄归人 2020-12-01 11:40

I\'ve searched everywhere for this answer but can\'t find it.

I\'m trying to come up with a script that will search for a particular subfolder then check if it conta

10条回答
  •  广开言路
    2020-12-01 12:20

    Check if the folder contains files:

    import os
    import shutil
    
    if len(os.listdir(folder_path)) == 0: # Check is empty..
        shutil.rmtree(folder_path) # Delete..
    

提交回复
热议问题