# -*- coding:utf-8 -*-__author__ = ' Magicpwn ' Import osimport timeimport os.pathimport pprintimport globpa = ' C:/xml/result/result.xls ' print Os.path.dirname (PA) print ' access time access time: ', time.ctime (Os.path.getatime (PA)) print ' Modified time modified: ', time.ctime (Os.path.getmtime (PA)) print ' Change time creation time: ', Time.ctime (Os.path.getctime (PA)) print ' File size: ', os.path.getsize (PA), ' Byte ' print ' is the file "', os.path.isfile (PA) print ' absolute absolute path > ', os.path.isabs (PA) print ' is the dir directory? ', os.path.isdir (PA) print ' Is the directory ', os.path.isdir (Os.path.dirname (PA)) print ' exist? ', os.path.exists (PA) print ' link exist ', os.path.lexists (PA) print ' is link ? ', Os.path.islink (PA) # os.path.walk () iterates through all the directories of a tree species, and invokes the provided function to pass the name of the directory name as a parameter to the function #os.mkdir (' c:/hh/') Create directory Def visit (arg, dirname, names): print dirname, arg, names for name in Names: subname = os.path.join (Dirname, name) #连接目录和文件名 print name# Traverse file Os.path.walk (Os.path.dirname (PA), visit, ' user data ') # wildcard find file For name in glob.glob (Os.path.dirname (PA) + '/[jr0-9]* '): print name
This article is from the "Magicpwn" blog, make sure to keep this source http://magicpwn.blog.51cto.com/10497784/1682081
Python directory traversal, wildcard lookup, file properties