How to delete a file or folder?

前端 未结 13 1338
青春惊慌失措
青春惊慌失措 2020-11-22 12:29

How do I delete a file or folder in Python?

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 13:06

    shutil.rmtree is the asynchronous function, so if you want to check when it complete, you can use while...loop

    import os
    import shutil
    
    shutil.rmtree(path)
    
    while os.path.exists(path):
      pass
    
    print('done')
    

提交回复
热议问题