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

首頁 > 編程 > Python > 正文

Python創建系統目錄的方法

2020-02-23 00:18:54
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金川县| 钦州市| 普陀区| 民和| 视频| 镇坪县| 龙山县| 伊通| 通辽市| 陆丰市| 集贤县| 永修县| 东莞市| 宿松县| 湖北省| 伊春市| 名山县| 渭南市| 阳朔县| 依安县| 西昌市| 潍坊市| 绥阳县| 和平区| 新邵县| 华容县| 达日县| 义马市| 綦江县| 申扎县| 城市| 楚雄市| 澄城县| 宁明县| 万宁市| 图木舒克市| 遂宁市| 汉阴县| 合山市| 瑞昌市| 朝阳县|