2

I'm trying to create a python script that when finished will search through a folder and retrieve some basic information about the files (most of which are MS Office) located within. Specifically I would like to get:

  • File Name
  • File Path
  • File Type
  • Date of Creation
  • Author
  • Date of Modification (if applicable)
  • Name of the user who modified the file (if applicable)

I've had some success so far getting a number of the values I need, however they are often incorrect and I believe this is because the information is retreived from the files general attributes rather than detailed information.

What I mean is that if you select an MS Office document, right click and go to properties you will see a number of tabs, the first being "general", this has some basic info including the date the file was created. However this date is actually when the file was made on the system/ drive. If you go to the details tab you can see the actual date the file was originally made.

This is the information I want to retrieve but I cannot figure out a way to access it. If someone could point me in the right direction I would be very grateful.

This is what I have so far...

    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!"
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.