Set Attr Meta write errors

I use a VB Macro to write metadata to my images. It basically takes my input into a form and creates a series of Set Attr Meta commands which are then executed to add the metadata to the file.

In 99 per cent of cases the macro works beautifully, but very occasionally the writes fail with a message that the System cannot find the file to which to write the metadata. It is a very infrequent problem but nonetheless a nuisance, as I lose all the metadata I have added to the file - and when that may be 50 plus keywords, a 60 word caption plus copyright info and you have to re-enter it, you can see the nuisance value.

For the last 12 months I have been trying to get a handle on the problem, but as it is so infrequent it is difficult to analyse. All I managed to ascertain is ghat the problem only seemed to occur with files larger that 1meg.

Unfortunately when I added a lot of metadata to multiple PSD files 20 plus megs in size I could not get the macro to fail once, which was baffling.

Then one day simply by chance, I caught the problem red-handed. I was adding metadata to a 2.5 meg jpg file.

Under normal circumstances when the metadata is being written the file flickers, presumably as it is being opened and closed to add the metadata. On this occasion, however, the file did not flicker, but as each field was being written a white temporary file appeared in the lister for a couple of seconds. This happened twice, before a got the dreaded "cannot find the file" message,

When I examined the lister I found the file had been renamed in the form filename.jpg1234 and hence the message. I also noticed that one of my disk drives was thrashing away.

The problem, it turns out, is the disk I use to write metadata to my images is partitioned into an NTFS volume and an Acronis Secure Zone, to which I regularly back up my system volume. Investigations showed that as the metadata writes were failing the disk was been hammered by Acronis writing to the secure zone.

Further work showed that whilst I could not produce the problem every time, the occurrence of failures increased very significantly if I wrote metadata whist Acronis was writing to its secure zone.

The solution, of course is obvious. I have moved the directory I use to write metadata to another hard drive, and the problem has disappeared. By coincidence I have also discovered that I have recovered my sanity.

Computers - don't you just love 'em?

You should be able to use a single SetAttr command to set all the metadata at once, which might also prevent the problem.

This is the form my commands look now in my script (obviously there are other lines for other fields):

ClickData.Func.Command.AddLine("SetAttr META ""imagedesc:" & captiona & """")
ClickData.Func.Command.AddLine("SetAttr META ""subject:" & subjecta & """")**
ClickData.Func.Command.AddLine("SetAttr META ""title:" & titlea & """")**

I did wonder whether there was a way to string them together. Could you point out how I might do that, as it must be far more efficient than what I am doing now?

Many thanks

(It should be all on one line. The examples are wrapped due to being wide.)

One of the advantages of of placing SET ATTR statements in a series of command lines is that I can only write the metadata that has actually changed to the image file. Very often the only changes may be the addition or reduction of keywords or the addiction of Special Instructions. In fact, I would say that happens 95 per cent of the time.

However, I have since read that even changing one field of image metadata can result in having to write all fields to the file, which would rather make my idea redundant and make Jon's one-shot solution a very good idea.

Before I embark on a major re-write of my macro, can you tell me is this what happens in Opus?

If your script is already filtering which lines it runs, it can just as easily filter which arguments it adds to a single line before running it. That would be a completely trivial change.

You can still do that with the single line method.