File properties

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

File properties

Ian Bartholomew-18
I thought this had been discussed before but I can't seem to find it in
the archive ....

I want to write a little Dolphin script to go through a couple of
hundred files and set some of the File properties (Author, Title,
Subject etc) as I don't really fancy doing it by hand in Explorer.

Any pointers on how to access a file's properties please...

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Christopher J. Demers
"Ian Bartholomew" <[hidden email]> wrote in message
news:c10lfu$1cboku$[hidden email]...
> I thought this had been discussed before but I can't seem to find it in
> the archive ....
>
> I want to write a little Dolphin script to go through a couple of
> hundred files and set some of the File properties (Author, Title,
> Subject etc) as I don't really fancy doing it by hand in Explorer.
>
> Any pointers on how to access a file's properties please...

Well, this is almost certainly not the officially sanctioned way, not a
complete solution, not robust, and depends upon NTFS, but.... ;)
This will open a stream on the ADS (Alternate Data Stream) that contains the
file properties.
fs := FileStream read: 'C:\test.txt:' , (Character codePoint: 5)
displayString , 'SummaryInformation' text: true.

It appears to be a sort of structure.  The data is certainly there.  If your
reading needs are simple you may be able to make a naive parser for it.
This page looks interesting: http://www.kyler.com/pubs/ddj9894.php .
Perhaps someone else knows a more complete and proper solution.  Let us know
what you end up with.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Ian Bartholomew-18
Chris,

Thanks for the info.  I used you code as a starting point for a snoop
round MSDN and came across pages talking about "IPropertyStorage" and
"IPropertySetStorage" which, I think, are the proper way to work with
these properties.  Unfortunately Dolphin doesn't have wrappers for them
and, in my complete ignorance of all things COM, I don't know how to add
them.

>Let us know what you end up with.

In the tradition of "if it works then do it" I had a play with your code
snippet and found that not only can you read the information that way
you can also write it as well.  I ended doing the following ....

I created a text file and edited it's author property to be 30 spaces
I then used your code snippet to read in a string from this file which
contains all the properties - including 30 spaces for the author

That step is necessary as creating a text file doesn't make the
properties available (so your code will fail) until one of the fields is
edited.

As the property String format returned is (I think) exactly the same for
each file I could then do a simple...

For each file
    Edit the author field in the blank property string to read what I
needed
    Write this property string to the file using the
':\005SummaryInformation'

>. Perhaps someone else knows a more complete and proper solution.

I've done what I need now but it would be nice to know the correct way
to do it :-)

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Chris Uppal-3
In reply to this post by Ian Bartholomew-18
Ian,

> I want to write a little Dolphin script to go through a couple of
> hundred files and set some of the File properties (Author, Title,
> Subject etc) as I don't really fancy doing it by hand in Explorer.

If you are not already looking at it, then:
    http://msdn.microsoft.com/library/en-us/stg/stg/ipropertysetstorage.asp
may help.  Particularly the subsection on the NTFS filesystem (which doesn't
seem to want to be linked to directly).

Also googling for 'StgOpenStorageEx' shows up a few things that might help,
such as
    http://www.howtodothings.com/showarticle.asp?article=447

It all looks a bit daunting to me...

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Ian Bartholomew-18
Chris,

> If you are not already looking at it, then:
>
>
http://msdn.microsoft.com/library/en-us/stg/stg/ipropertysetstorage.asp
> may help.  Particularly the subsection on the NTFS filesystem (which
> doesn't seem to want to be linked to directly).

Thanks.  I had come across those pages but, to be honest, couldn't
understand what they were talking about.  I'm sure it makes sense to
someone who has taken the time to learn about COM but for somebody who
just wants to _do_ something (in the simplest way possible) they aren't
a lot of use.  That's the way it is now though I suppose.....

> It all looks a bit daunting to me...

I would say that's an understatement :-)

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Chris Uppal-3
Ian,

> I'm sure it makes sense to
> someone who has taken the time to learn about COM but for somebody who
> just wants to _do_ something (in the simplest way possible) they aren't
> a lot of use.

That's my impression of COM in general, or at least of its applications.

Not to mention MS APIs in general.  Simplicity and elegance don't seem to
appear in the MS dictionary at all.

Sometime I must check Encarta to see what that has to say about the subjects --
"Terms used in pre-industrial design theory; now  replaced by <insert buzzword
here> and considered obsolete by most experts"...

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Christopher J. Demers
In reply to this post by Ian Bartholomew-18
"Ian Bartholomew" <[hidden email]> wrote in message
news:c127gk$1d5oa1$[hidden email]...
> Chris,
>
> Thanks for the info.  I used you code as a starting point for a snoop
> round MSDN and came across pages talking about "IPropertyStorage" and
> "IPropertySetStorage" which, I think, are the proper way to work with
> these properties.  Unfortunately Dolphin doesn't have wrappers for them
> and, in my complete ignorance of all things COM, I don't know how to add
> them.
...
> >. Perhaps someone else knows a more complete and proper solution.
>
> I've done what I need now but it would be nice to know the correct way
> to do it :-)

I have not tried this yet, but MS has an ActiveX DLL intended to be used
from VB to access and change document properties.  I think it should work
from Dolphin rather easily.

"Dsofile.exe is a self-extracting executable that provides a simple
in-process ActiveX component for programmers to use in order to read and
modify the Document Summary Properties for an OLE Structured Storage file
such as native Excel, PowerPoint, Microsoft Visio, and Word documents
without using Automation to Microsoft Office. The component can also work on
non-OLE documents when it is run on Windows 2000 with an NTFS file system. "

You can read more about it and download here (url may wrap):
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q224/3/51.asp&NoWebContent=1

Chris


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Christopher J. Demers
"Christopher J. Demers" <[hidden email]> wrote in
message news:c13o7g$1eli8q$[hidden email]...
> I have not tried this yet, but MS has an ActiveX DLL intended to be used
> from VB to access and change document properties.  I think it should work
> from Dolphin rather easily.
>
> "Dsofile.exe is a self-extracting executable that provides a simple
> in-process ActiveX component for programmers to use in order to read and
...

I just tried it, and it works great.  I generated the ActiveX classes from
the wizard.  Here is my test code:
===============
reader := DSOleFile_PropertyReader new.
properties := reader getDocumentProperties: 'C:\temp\test.txt'.
"Display the author."
properties author.
"Set the author."
properties author: 'New Author'.
properties := nil.
reader := nil.
===============

Chris


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Ian Bartholomew-18
Chris,

> I just tried it, and it works great.  I generated the ActiveX classes
> from the wizard.  Here is my test code:

Many thanks for pointing this out.  My original hack had worked but this
makes it _much_ easier to tidy things up and programmatically make
updates.

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Don Rylander-3
In reply to this post by Ian Bartholomew-18
Ian,
"Ian Bartholomew" <[hidden email]> wrote in message
news:c10lfu$1cboku$[hidden email]...
[...]
> I want to write a little Dolphin script to go through a couple of
> hundred files and set some of the File properties (Author, Title,
> Subject etc) as I don't really fancy doing it by hand in Explorer.
>
> Any pointers on how to access a file's properties please...

I was able (in D4 IIRC?) to use IFile and IStorage (both in the image) to
get dangerously close to something useful with so-called compound documents
before I ran out of time. You may have to go down through IFileSystem to get
there, but I don't recall.  I do recall wishing there were a few more
structures predefined, but I suspect my knowledge of COM would rank
somewhere below yours ;^).

HTH,

Don

>
> --
> Ian
>
> Use the Reply-To address to contact me.
> Mail sent to the From address is ignored.
>


Reply | Threaded
Open this post in threaded view
|

Re: File properties

Ian Bartholomew-18
Don,

Thanks for the reply.  The dll that Chris pointed out has proved to be a
solution for my simple needs but it might be useful to have a solution
that is implemented within Dolphin and which doesn't need an extra dll.

> I was able (in D4 IIRC?) to use IFile and IStorage (both in the
> image) to get dangerously close to something useful with so-called
> compound documents before I ran out of time.

I've got a wrapper around IFileSystem (and have used IStorage in the
past) but when I had a look at them I couldn't see a way of getting to
the File's properties from there.  I even tried the trick (?) that Chris
mentioned, appending 16r05 followed by "SummaryInformation" to the
filename, but it didn't seem to do anything.  I'm sure I must have
missed something though [1]

One of those projects for the future....

[1] Something else I missed.  Around 20% of the documents I wanted to
edit the properties of are rtf files.  I have my machine set up so that
rtf files default to being opened/edited in Wordpad as it is so much
faster than Word and is quite suitable for my editing needs.  I now
discover that Wordpad, because it's so old I suppose, knows nothing
about properties and resets them all to empty strings when the file is
saved.  Aaaaargh!

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.