Python程序问题求解
要求:列出指定目录”c:\”所有的后缀名为*.txt的文件(包括子文件夹内所有文件),并输出每个文件的创建日期和大小importosimportfnmatchimport...
要求:列出指定目录”c:\”所有的后缀名为*.txt 的文件(包括子文件夹内所有文件),并输出每个文件的创建日期和大小
import osimport fnmatchimport 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)
然后
求修改的程序。。 展开
import osimport fnmatchimport 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)
然后
求修改的程序。。 展开
1个回答
展开全部
import os
import fnmatch
import time
def findfiles(path, fnmatchex='*.*'):
for root, dirs, files in os.walk(path):
for filename in fnmatch.filter(files,fnmatchex):#这个位置你写反了
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"d:\\", "*txt"):
print filename, filesize, strtimestamp(createtime)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询