Daily Work: program 1
Topic sourcedir /l 缺少功能:统计目录和文件的总字节
# -*- coding: utf-8 -*-
__author__ = 'admin'
import os
import time
# #查看文件的大小
# print(statinfo.st_size)
# #查看是否为目录
# print(os.path.isdir(x))
# #查看当前路径
# print(os.path.abspath('.'))
def dirL():
currentpath = os.getcwd()
direction = os.listdir(currentpath)
dirl = [x.lower() for x in direction]
#查看文件的属性,st_ctime:最近修改时间,st_size文件大小
statinfo = os.stat(x)
#格式化时间戳
timeArray = time.localtime(statinfo.st_ctime)
regTime = time.strftime("%Y/%m/%d %H:%M", timeArray)
size = statinfo.st_size
if os.path.isdir(x):
return regTime + ' ' + str(size) +' ' + x
else:
return regTime + ' <DIR>' +' '+ str(size) + ' ' + x
L = map(prepo,dirl)
return list(L)
[print(x) for x in dirL()]
- 1
无愠无殇