import os
import fnmatch
import time
def findfiles(path, fnmatchex='*.*):
for root, dirs, files in os.walk(path):
for filename in fnmatch.filter(fnmatchex, files):
fullname = os.path.join(root, filename)
filestat = os.stat(fullname)
yield fullname, filestat.st_size, filestat.st_ctime
def strtimestamp(timestamp):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
for filename, filesize, createtime in findfiles(r"C:\", "*.txt"):
print filename, filesize, strtimestamp(createtime)
追问那个 我用的是window7的Python3.3.5版本
追答import os
import fnmatch
import time
def findfiles(path, fnmatchex='*.*'):
for root, dirs, files in os.walk(path):
for filename in fnmatch.filter(fnmatchex, files):
fullname = os.path.join(root, filename)
filestat = os.stat(fullname)
yield fullname, filestat.st_size, filestat.st_ctime
def strtimestamp(timestamp):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
for filename, filesize, createtime in findfiles(r"C:\", "*.txt"):
print filename, filesize, strtimestamp(createtime)