Python創(chuàng)建系統(tǒng)目錄的方法
本文實例講述了Python創(chuàng)建系統(tǒng)目錄的方法。分享給大家供大家參考。具體如下:
Python2 mkdir在沒有上級目錄時創(chuàng)建會失敗.該方法可以創(chuàng)建多級目錄。
/temp/gapgers/upload/images/1.png
如過temp文件夾不存在,會創(chuàng)建空的文件夾/temp/gapgers/upload/images/以及空文件1.png。
該方法只做拋磚引玉,大神勿噴
def mkfilePower(path):
'''create dirs if the path contain a file create a empty file
if the dir's file is exist return False else return True
ex:path = r'c:/temp/gapgers/upload/images/1.png'
nomatter there have dir temp or not,we will create it and create a empty file 1.png
'''
paths = path.split('/')
temppath = ''
for index,_spilt in enumerate(paths):
if index == 0:
temppath = _spilt
continue
temppath = temppath + '/' + _spilt
if os.path.isdir(temppath):
pass
elif index == len(paths)-1:
if os.path.isfile(temppath):
return False
fl = open(temppath,'w')
fl.close()
else:
os.mkdir(temppath)
return True
希望本文所述對大家的Python程序設(shè)計有所幫助。
相關(guān)文章
OpenCV基礎(chǔ)HSV顏色空間*args與**kwargs滑動條傳參問題
這篇文章主要介紹了OpenCV基礎(chǔ)中HSV顏色空間*args與**kwargs滑動條傳參問題的詳細解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-10-10使用Python一鍵提取PDF中的表格到Excel的方法詳解
從PDF文件獲取表格中的數(shù)據(jù),也是日常辦公容易涉及到的一項工作,一個一個復(fù)制吧,效率確實太低了,用Python從PDF文檔中提取表格數(shù)據(jù),并寫入Excel文件,灰?;页8咝?本文就給大家介紹一下如何使用Python一鍵提取PDF中的表格到Excel,需要的朋友可以參考下2023-08-08詳解如何用TensorFlow訓(xùn)練和識別/分類自定義圖片
這篇文章主要介紹了詳解如何用TensorFlow訓(xùn)練和識別/分類自定義圖片,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08