os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径
os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd
os.curdir 返回当前目录: ('.')
os.pardir 获取当前目录的父目录字符串名:('..')
os.makedirs('dirname1/dirname2') 可生成多层递归目录
os.removedirs('dirname1') 若目录为空,则删除,并递归到上一级目录,如若也为空,则删除,依此类推
os.mkdir('dirname') 生成单级目录;相当于shell中mkdir dirname
os.rmdir('dirname') 删除单级空目录,若目录不为空则无法删除,报错;相当于shell中rmdir dirname
os.listdir('dirname') 列出指定目录下的所有文件和子目录,包括隐藏文件,并以列表方式打印
os.remove() 删除一个文件
os.rename("oldname","newname") 重命名文件/目录
os.stat('path/filename') 获取文件/目录信息
os.symlink('path/filename','ln_filename') 创建符号链接,源需绝对路径
os.utime() 修改时间属性
>>> import os
>>> stinfo = os.stat('c.py')
>>> print "access time of c.py: %s \nmodified time of c.py: %s" % (stinfo.st_atime,stinfo.st_mtime)
access time of c.py: 1375448908.0
modified time of c.py: 1369735909.0
>>> os.utime('c.py',(1375448978,1369735977))
>>> print "access time of c.py: %s \nmodified time of c.py: %s" % (stinfo.st_atime,stinfo.st_mtime)
access time of c.py: 1375448908.0
modified time of c.py: