1.判断文件是否存在:os.path.exists(r"c://python//hello.py")--->true/false
2.判断是否是绝对路径:os.path.isabs(r"c://python//hello.py")
3.判断是否是目录:os.path.isdir(dirpath)
4.判断是否是文件:os.path.isfile(filepath)
5.判断是否是链接文件:os.path.islink(linkpath)
6.获取文件大小:os.path.getsize(filename)
7.搜索目录下的所有文件:os.path.walk()
8.文件的访问时间:os.path.getatime() #这里的时间以秒为单位,并且从1970年1月1日开始算起
9.文件的修改时间:os.path.getmtime(myfile)
10.复制单个文件:shultil.copy(oldfile,newfile)
11.复制整个目录树:shultil.copytree(r".\setup",r".\backup")
12.删除整个目录树:shultil.rmtree(r".\backup")
13.创建一个唯一的临时文件:tempfile.mktemp()--->filename
14.打开临时文件:tempfile.T
网友评论