python——在文件存放路径下自动创建文件夹!

1、a.py文件存放的路径下为(D:\Auto\eclipse\workspace\Testhtml\Test)

2、通过os.getcwd()获取的路径为:D:\Auto\eclipse\workspace\Testhtml\Test

3、使用os.getcwd()[:-4]截取到的路径为:D:\Auto\eclipse\workspace\Testhtml\

4、使用下面的命令则在3步骤下新建report文件夹,并将执行的结果会自动保存在report文件夹下

 

import os
File_Path = os.getcwd()[:-4] +'report\\' #获取到当前文件的目录,并检查是否有report文件夹,如果不存在则自动新建report文件 if not os.path.exists(File_Path): os.makedirs(File_Path)

 

posted @ 2017-06-12 15:49  Syw_文  阅读(18884)  评论(0编辑  收藏  举报