国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python創建系統目錄的方法

2019-11-25 17:57:41
字體:
來源:轉載
供稿:網友

本文實例講述了Python創建系統目錄的方法。分享給大家供大家參考。具體如下:

Python2 mkdir在沒有上級目錄時創建會失敗.該方法可以創建多級目錄。
/temp/gapgers/upload/images/1.png
如過temp文件夾不存在,會創建空的文件夾/temp/gapgers/upload/images/以及空文件1.png。
該方法只做拋磚引玉,大神勿噴

復制代碼 代碼如下:
import os
    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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳西县| 上犹县| 十堰市| 洪湖市| 鹤山市| 禹城市| 丹棱县| 鸡东县| 九龙城区| 安阳县| 屏东县| 扶余县| 沙坪坝区| 绥棱县| 泰顺县| 盈江县| 西盟| 平顶山市| 肥东县| 铁岭县| 蚌埠市| 福贡县| 贺州市| 砀山县| 商南县| 通城县| 大同市| 溆浦县| 独山县| 鄂伦春自治旗| 会同县| 定西市| 上高县| 南阳市| 喜德县| 永川市| 沽源县| 英吉沙县| 龙州县| 甘肃省| 萝北县|