def listdir_stat(dirname):
"""Returns a list of tuples for each file contained in the named
directory, or None if the directory does not exist. Each tuple
contains the filename, followed by the tuple returned by
calling os.stat on the filename.
"""
import os
def stat(filename):
rstat = os.stat(filename)
if IS_UPY:
# Micropython dates are relative to Jan 1, 2000. On the host, time
# is relative to Jan 1, 1970.
return rstat[:7] + tuple(tim + TIME_OFFSET for tim in rstat[7:])
return tuple(rstat) # PGH formerly returned an os.stat_result instance
try:
files = os.listdir(dirname)
except OSError:
return None
if dirname == '/':
return list((file, stat('/' + file)) for file in files)
return list((file, stat(dirname + '/' + file)) for file in files)
评论列表
文章目录