import os,time currentdir = os.getcwd() filenum, filesize, dirnum = 0, 0, 0 for name in os.listdir(currentdir): if os.path.isfile(name): print('%s\t\t%d\t%s' % (time.strftime('%Y/%m/%d %H:%M', time.localtime(os.path.getmtime(name))), os.path.getsize(name), name)) filenum += 1 filesize += os.path.getsize(name) elif os.path.isdir(name): print('%s\t<DIR>\t\t%s' % (time.strftime('%Y/%m/%d %H:%M', time.localtime(os.path.getmtime(name))), name)) dirnum += 1 print('\t\t%d个文件\t\t%d 字节' % (filenum, filesize)) print('\t\t%d个目录' % dirnum)
能不能解释下题目的意思啊
个人理解题目是想要模拟实现命令行下输入dir之后得到的效果。
Sign in to make a reply
梦想家高先森