os模块:
os.path.exists(path) -->bool #(path)文件或者目录存在
os.path.abspath(path) -->str #(path)返回文件或者目录的绝对路径
# 下面几个顾名思其义吧
os.path.isfile(path) -->bool
os.path.isdir(path) -->bool
os.path.islink(path) -->bool
os.path.join(p_parent,p_sub) -->str #返回新的path,父路径+新路径
os.path.relpath(path[, start]) -->str #返回相对路径
os.sep -->返回系统的分隔符==java的File.seperator
os.path.getsize(path) -->long 返回文件的size
#返回一个三元元组
os.walk(dpath)
(目录abspath,[子目录list],[子文件list])
readfile.py:
#/bin/python
import os
for p in os.walk("D:\prj\py\part11_file\pfiles"):
print p
目录结构:D:\prj\py\part11_file
('D:\\prj\\py\\part11_file\\pfiles', ['dir1', 'dir2'], ['log.log', 'readfile.py', 'sometext.txt', 'stories.txt']) ('D:\\prj\\py\\part11_file\\pfiles\\dir1', ['dir_par'], ['a.txt']) ('D:\\prj\\py\\part11_file\\pfiles\\dir1\\dir_par', [], ['log.log']) ('D:\\prj\\py\\part11_file\\pfiles\\dir2', [], ['readfile.py', 'stories.txt'])