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.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM