方法1:这个很简单其实就是考察os.path.exists()
的使用
# -*- coding: utf-8 -*-
import os
import sys
def dir_test(testdirs):
""" Tests to see if the directory testdir exists, if not it will create the directory for you. """
if not os.path.exists(testdirs):
os.makedirs(testdirs)
if __name__ == '__main__':
testdirs = '/home/work/test/world'
dir_test(testdirs)

注
基本与github给出的一致
https://github.com/geekcomputers/Python/blob/master/dir_test.py
网友评论