您好,我正在编写一个Python脚本,该脚本将映射到列表(或任何其他对象),并且列表的每个单元格中都有6个项目:
我是python的新手,我尝试了我所知道的一切...
有帮助吗?
谢谢 :)
哦,拜托,继续在Google上搜索“ python show file information”,这是出现的第一件事:
This function takes the name of a file, and returns a 10-member tuple with the following contents:
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)
然后,转到python的文档,您将找到参数的含义:
st_mode - protection bits,
st_ino - inode number,
st_dev - device,
st_nlink - number of hard links,
st_uid - user id of owner,
st_gid - group id of owner,
st_size - size of file, in bytes,
st_atime - time of most recent access,
st_mtime - time of most recent content modification,
st_ctime - platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows)
然后,您将看到如何列出dir函数,该函数也在名为的文档中listdir
。不要告诉我这很辛苦,花费了我1分钟。
这是使用DFS遍历低谷文件夹的方法(深度优先搜索):
import os
def list_dir(dir_name, traversed = [], results = []):
dirs = os.listdir(dir_name)
if dirs:
for f in dirs:
new_dir = dir_name + f + '/'
if os.path.isdir(new_dir) and new_dir not in traversed:
traversed.append(new_dir)
list_dir(new_dir, traversed, results)
else:
results.append([new_dir[:-1], os.stat(new_dir[:-1])])
return results
dir_name = '../c_the_hard_way/Valgrind/' # sample dir
for file_name, stat in list_dir(dir_name):
print file_name, stat.st_size # sample with file size
剩下的我留给你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句