?
Solved

win32com with Common file types

Posted on 2005-03-30
5
Medium Priority
?
544 Views
Last Modified: 2012-06-21
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!
0
Comment
Question by:DKProthro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Author Comment

by:DKProthro
ID: 13663850
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
 

Expert Comment

by:BruceDWebber
ID: 13679003
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
 

Author Comment

by:DKProthro
ID: 13682141
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 15711390
PAQed with points refunded (200)

Computer101
EE Admin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question