我正在尝试创建一个python脚本,当它完成后,它将搜索一个文件夹,并检索有关位于其中的文件(大多数是msoffice)的一些基本信息。我特别想得到:
到目前为止,我已经成功地获得了一些我需要的值,但是它们通常是不正确的,我相信这是因为信息是从文件的一般属性中检索出来的,而不是从详细信息中检索的。在
我的意思是,如果你选择一个msoffice文档,右键单击并转到属性,你会看到许多选项卡,第一个是“常规”,其中包含一些基本信息,包括文件的创建日期。但是这个日期实际上是在系统/驱动器上生成文件的日期。如果转到“详细信息”选项卡,则可以看到文件最初生成的实际日期。在
这是我想检索的信息,但我想不出一种方法来访问它。如果有人能为我指出正确的方向,我将不胜感激。在
这就是我目前所拥有的。。。在
import os, os.path, time, csv
from os import stat
dataCSV="C:\Cos\Inventory\hello.csv"
FOLDERPATH="C:\Cos\New folder\\"
columnHeader = "Sub-Folder Path,Type,Name,Document Type,Date Created,Created By,Date Modified,Modified By,Notes"
with open(dataCSV, 'wb') as f:
writer = csv.writer(f)
f.write(columnHeader)
f.write("\n")
for filename in os.listdir(FOLDERPATH):
fullPath = os.path.join(FOLDERPATH, filename)
f.write(os.path.join(FOLDERPATH, filename))
f.write(",")
fullNameSplit = filename.rsplit('.',1)
f.write(fullNameSplit[1])
f.write(",")
f.write(fullNameSplit[0])
f.write(",")
f.write("' ',")
f.write(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(os.path.getctime(fullPath))))
f.write(",")
f.write(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(os.path.getmtime(fullPath))))
f.write("\n")
f.close()
print "Done!"
目前没有回答
相关问题 更多 >
编程相关推荐