新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎樣創(chuàng)建文件目錄
創(chuàng)建文件目錄

創(chuàng)新互聯(lián)技術(shù)團(tuán)隊(duì)10多年來致力于為客戶提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、營(yíng)銷型網(wǎng)站建設(shè)、搜索引擎SEO優(yōu)化等服務(wù)。經(jīng)過多年發(fā)展,公司擁有經(jīng)驗(yàn)豐富的技術(shù)團(tuán)隊(duì),先后服務(wù)、推廣了上1000+網(wǎng)站,包括各類中小企業(yè)、企事單位、高校等機(jī)構(gòu)單位。
import os def mkdir(path): folder = os.path.exists(path) if not folder: #判斷是否存在文件夾如果不存在則創(chuàng)建為文件夾 os.makedirs(path) #makedirs 創(chuàng)建文件時(shí)如果路徑不存在會(huì)創(chuàng)建這個(gè)路徑 print "--- new folder... ---" print "--- OK ---" else: print "--- There is this folder! ---" file = "G:\\xxoo\\test" mkdir(file) #調(diào)用函數(shù)
os.getcwd()可以查看py文件所在路徑;
在os.getcwd()后邊 加上 [:-4] + 'xxoo\\' 就可以在py文件所在路徑下創(chuàng)建 xxoo文件夾
import os folder = os.getcwd()[:-4] + 'new_folder\\test\\' #獲取此py文件路徑,在此路徑選創(chuàng)建在new_folder文件夾中的test文件夾 if not os.path.exists(folder): os.makedirs(folder)
推薦學(xué)習(xí)《Python教程》!
文章題目:創(chuàng)新互聯(lián)Python教程:python怎樣創(chuàng)建文件目錄
文章URL:http://fisionsoft.com.cn/article/dpsjghg.html


咨詢
建站咨詢
