python 删除非空目录 shutil.rmtree

import shutil
shutil.rmtree(new_folder_path)
import os
import shutil

if __name__ == '__main__':
    new_folder_path = "./new_folder"
    if os.path.exists(new_folder_path)==False:
        os.mkdir(new_folder_path)
    print(os.path.exists(new_folder_path))
    new_file_path = new_folder_path+"/1.txt"
    file = open(new_file_path, "w", encoding='utf-8')
    file.write("123456")
    file.close()
    print(os.path.exists(new_file_path))
    shutil.rmtree(new_folder_path)
    print(os.path.exists(new_folder_path))
    print(os.path.exists(new_file_path))
文章目录