python判断文件和文件夹是否存在、创建文件夹

>>> importos
>>>os.path.exists('d:/assist')
True
>>>os.path.exists('d:/assist/getTeacherList.py')
True
>>>os.path.isfile('d:/assist')
False
>>>os.path.isfile('d:/assist/getTeacherList.py')
True
>>>os.makedirs('d:/assist/set')
>>>os.path.exists('d:/assist/set')
True

遍历文件夹
参考
>>> defTest2(rootDir):
... for lists in os.listdir(rootDir):
... path = os.path.join(rootDir, lists)
... print path
... if os.path.isdir(path):
... Test2(path)
...
>>>Test2("F:zr")
原文地址:https://www.cnblogs.com/chenjianhong/p/4144526.html