大连网站建设详细流程,镇江网站,wordpress域名修改后,管理平台登录界面本文实例讲述了Python创建系统目录的方法。分享给大家供大家参考。具体如下#xff1a;Python2 mkdir在没有上级目录时创建会失败.该方法可以创建多级目录。/temp/gapgers/upload/images/1.png如过temp文件夹不存在#xff0c;会创建空的文件夹/temp/gapgers/upload/images/以…本文实例讲述了Python创建系统目录的方法。分享给大家供大家参考。具体如下Python2 mkdir在没有上级目录时创建会失败.该方法可以创建多级目录。/temp/gapgers/upload/images/1.png如过temp文件夹不存在会创建空的文件夹/temp/gapgers/upload/images/以及空文件1.png。该方法只做抛砖引玉大神勿喷复制代码 代码如下:import osdef mkfilePower(path):create dirs if the path contain a file create a empty fileif the dirs file is exist return False else return Trueex:path rc:/temp/gapgers/upload/images/1.pngnomatter there have dir temp or not,we will create it and create a empty file 1.pngpaths path.split(/)temppath for index,_spilt in enumerate(paths):if index 0:temppath _spiltcontinuetemppath temppath / _spiltif os.path.isdir(temppath):passelif index len(paths)-1:if os.path.isfile(temppath):return Falsefl open(temppath,w)fl.close()else:os.mkdir(temppath)return True希望本文所述对大家的Python程序设计有所帮助。本文标题: Python创建系统目录的方法本文地址: http://www.cppcns.com/jiaoben/python/120635.html