Accessing Windows file metadata?

E

EP

I'm looking for a method by which to access Windows files metadata and
have not been able to find anything in the standard modules or via
Google - what is the standard approach?

Shamefully I really do not understand Windows file system - e.g. is
properties metadata attached to the file? if I change that metadata
do I change the file's hash? how is the metadata structured? or is
the "properties" metadata simply derived upon access?

Either way, is there a module or method to access this metadata (I'd
hope there was a metadata dictionary for each file, but that may be a
sign I've been spoiled by Python) ?


EP
 
R

Roger Upole

The Pywin32 package wraps the interfaces used to read and
write these properties. \win32com\test\testStorage.py demonstrates
how to use them.

There are actually two different ways that metadata is stored.
For structured storage files created by COM applications, it's
embedded directly in the file data. This would change the file's hash
if the document properties were changed. On volumes formatted
with NTFS 5 (Win2k and later), document properties can be added
to any type of file and are stored in alternate data streams.

hth
Roger
 
J

John Rhoads

Probably somebody more deeply into this will soon give you a better answer,
but I'll
try to give a better-than-nothing answer.

The Properties metadata that you see in the shell can come from several places.
The oldest, commonest source is from Microsoft Office files. These have a
compound
structure associated with OLE Object Linking and Embedding and the metadata
is just one
of a lot of things stuck in there besides the Word text or Excel numbers
you see in the
application.

Getting to it from Python is via COM. See Mark Hammond and Andy Robinson's
book
"Python Programming in Win32" for the general approach. Perhaps the easiest
way to
get this metadata is using DSOFILE.DLL that was released as an example a long
time ago by Microsoft (it's not an OS file, you have to install it yourself).


The following article gives a VBScript example that you can
use as a template for your Python.

http://www.microsoft.com/technet/community/columns/scripts/sg0305.mspx

As I said, the OLE metadata has been around for a long time. With Windows
2000, MS
extended the idea to any NTFS file so that you have an open-ended ability to
associate named attributes like author, title, keywords or custom attributes
of your
own to any file on an NTFS partition.

Unfortunately DSOFILE does not help with this (at least I don't think so!),
so you'd need
to deal with the OS at a somewhat uglier level. And obviously you need Win2K
or better.

Look at \win32com\test\testStorage.py in the win32 python package for an
example.

Hope this helps,


John Rhoads
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top