Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4203373
  • 博文数量: 176
  • 博客积分: 10059
  • 博客等级: 上将
  • 技术积分: 4681
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-24 12:27
文章分类

全部博文(176)

文章存档

2012年(1)

2011年(4)

2010年(14)

2009年(71)

2008年(103)

分类: Python/Ruby

2009-07-24 09:06:28

os和os.path模块
os.listdir(dirname):列出dirname下的目录和文件
os.getcwd():获得当前工作目录
os.curdir:返回但前目录('.')
os.chdir(dirname):改变工作目录到dirname

os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false
os.path.isfile(name):判断name是不是一个文件,不存在name也返回false
os.path.exists(name):判断是否存在文件或目录name
os.path.getsize(name):获得文件大小,如果name是目录返回0L
os.path.abspath(name):获得绝对路径
os.path.normpath(path):规范path字符串形式
os.path.split(name):分割文件名与目录(事实上,如果你完全使用目录,它也会将最后一个目录作为文件名而分离,同时它不会判断文件或目录是否存在)
os.path.splitext():分离文件名与扩展名
os.path.join(path,name):连接目录与文件名或目录
os.path.basename(path):返回文件名
os.path.dirname(path):返回文件路径



def __scanDir( self, dir ):
        for root, dirs, files in os.walk( dir, topdown=True):
            for name in files:
                path = os.path.join(root, name);
                if name == RmLogFile.LOG_FILE_NAME and os.path.isfile( path ):
                    
                    os.remove( path )
                    print "Find a file, remove it:", path
            for name in dirs:
                if name not in RmLogFile.EXCLUDE_PATHS:
                    self.__scanDir( name )

阅读(2593) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~