win32com with Common file types

I'm writing a series of functions to grab the Date Created field for different file types. I've been successful for Word, Excel, Powerpoint and Visio. I'm currently trying to write a function for MS Project, but am getting stuck. I need a program that will open an MS Project file, find the Date/Time it was created and then close the file. My code for Visio is as follows:

import sys, win32com.client

doc = sys.argv[1]

try:
      visio = win32com.client.Dispatch("Visio.Application")
      visio.Visible = 0
      try:
            dwg = visio.Documents.Open(doc)
            print dwg.TimeCreated, ",", dwg.TimeSaved
      except Exception, e:
            print "Error", e

      dwg.Close()
      visio.Quit()
except Exception, e:
      print "Error opening file",e
 
I would also greatly appreciate any ideas on how to do something similar for PDF and other common filetypes (I haven't started looking at this yet). Thanks!
DKProthroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DKProthroAuthor Commented:
I found a solution for MS Project, but now I need solutions for non-MS file types (PDF, images, movies, ZIP). My code for MS Project is:

import sys, win32com.client

doc = sys.argv[1]

try:
      mpp = win32com.client.Dispatch("MSProject.Application")
      mpp.Visible = 1
      try:
            mpp.FileOpen(doc)
            proj = mpp.ActiveProject
            print proj.BuiltinDocumentProperties(11), ",", proj.BuiltinDocumentProperties(12)
      except Exception, e:
            print "Error", e

      mpp.FileSave()
      mpp.Quit()
except Exception, e:
      print "Error opening file",e
0
BruceDWebberCommented:
Rather than look inside the file for this information, you can get this information from the operating system. The OS stores the create time, access time and the time modified, as seconds since the start of the Epoch. Python has functions, in the time module, for converting this number into time structures and strings. This works regardless of the file type.

For example:

-----

import os
import time

print "Time created: " + time.ctime(os.path.getctime('c:\\test.doc'))
print "Time modified: " + time.ctime(os.path.getatime('c:\\test.doc'))

-----

getctime returns the create time, as the number of seconds since the start of the Epoch. Similarly, getatime returns the access time and getmtime the time modified. time.ctime converts this into a string, but you can also convert these into a time structure that will let you access the year, month, day, etc. separately.

Here's the relevant Python documentation:
http://www.python.org/dev/doc/devel/lib/module-os.path.html for os.path
http://www.python.org/doc/2.3/lib/module-time.html for time

Regards,
Bruce
0
DKProthroAuthor Commented:
Sorry, I should have gone into more detail about what I'm looking for. The files I'm interested in are uploaded to a server, so the OS time the server shows is really just the upload time, not the actual file-creation date. Most filetypes store the actual file creation date in their metadata, its just a matter of getting at it.

So far, I've been successful with Microsoft's file-types, but not with any others. Using COM is a solution I think will work, I'm just not totally sure how to do it. Any other solutions are welcome though.
0
Computer101Commented:
PAQed with points refunded (200)

Computer101
EE Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.