python 获取目录下的文件信息

获取某个目录下深度为1的目录和文件的大小和最近的修改时间:

for item in os.listdir(request_path):
	full_path = os.path.join(request_path,item)
	fsize = os.path.getsize(full_path)
	fmtime = timeStampToTime(os.path.getmtime(full_path))
	if os.path.isdir(full_path):
		file_list['dirs'].append({'name':item,'fsize':str(fsize)+'KB','fmtime':fmtime})
	else:
		file_list['files'].append({'name':item,'fsize':fsize,'fmtime':fmtime})


猜你喜欢

转载自blog.csdn.net/u011085172/article/details/79044854