Python基础之创建文件夹与删除文件夹。

参考链接:https://blog.csdn.net/weixin_43826242/article/details/87101436

创建目录结构

# 创建文件目录结构
def create_folder(folder_name):
    result_data = 0
    folder_name_exist = os.path.exists(folder_name)
    if not folder_name_exist:
        os.makedirs(folder_name)
    if not os.path.exists(folder_name):
        result_data = 1
    return result_data

 

 

删除文件夹(文件夹里面有文件的情况)

def delete_folder(path):
    for i in os.listdir(path):
        path_file = os.path.join(path, i)
        if os.path.isfile(path_file):
            os.remove(path_file)
        else:
            delete_folder(path_file)
    os.removedirs(path)

 

 

ok.

 

posted @ 2020-04-30 09:22  o云淡风轻o  阅读(1501)  评论(0编辑  收藏  举报