Failure to overwrite original files- randomly

Started by ArnieR, March 29, 2023, 12:41:43 PM

Previous topic - Next topic

ArnieR

I am using Windows 11, Exiftool Version 12.57
Using Visual Studio and C#, I have created an App to display metadata, map GPS position, and update metadata fields - currently testing overwriting the XPComment tag.  My App calls ExifTool using the code provided by https://exiftool.org/forum/index.php?topic=11286.0 Call ExifTool from C#.

Everything has worked great, except that occasionally, but consistently randomly, the overwrite_original command fails for an unknown reason.  When it does fail, the original file simply disappears from the folder.  I have been unable to locate the file anywhere (it's not in a subdirectory, nor Recycle bin.)
I have created a debug output file showing the ExifTool commands and responses.  The output below shows the overwrite working, and then suddenly failing.  (Note that the commands to ExifTool are printed out using semi-colon( ; ) as a parameter separator for debug print purposes.)  There are 5 successful commands to overwrite the XPComment, and then a failure, at which time the file has disappeared from the folder. 

As previously mentioned, the occurrence of the failure is random - sometimes it fails on the first attempt, other times many commands later.  Each test starts with the same original .jpg image.  I have tested it on several different jpgs with similar results.  (My original picture had no EXIF tags, but that doesn't seem to be a factor here - many times ExifTool successfully added the EXIF tags with the XPComment without failure.)

I did find this topic: https://exiftool.org/forum/index.php?topic=10459.0, which has some similarities to my observations. 

<------My debug output follows:>
-overwrite_original; -XPComment=bla bla bla bla vvv; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
    1 image files updated
{ready}
-s; -XPComment; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
XPComment                      : bla bla bla bla vvv
{ready}
-overwrite_original; -XPComment=bla bla bla bla vvv; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
    1 image files updated
{ready}
-s; -XPComment; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
XPComment                      : bla bla bla bla vvv
{ready}
-overwrite_original; -XPComment=bla bla bla bla vvv; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
    1 image files updated
{ready}
-s; -XPComment; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
XPComment                      : bla bla bla bla vvv
{ready}
-overwrite_original; -XPComment=bla bla bla bla vvv; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
    1 image files updated
{ready}
-s; -XPComment; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
XPComment                      : bla bla bla bla vvv
{ready}
-overwrite_original; -XPComment=bla bla bla bla vvv; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
    1 image files updated
{ready}
-s; -XPComment; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
XPComment                      : bla bla bla bla vvv
{ready}
-overwrite_original; -XPComment=bla bla bla bla vvv; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
    0 image files updated
    1 files weren't updated due to errors
{ready}
-s; -XPComment; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
XPComment                      : bla bla bla bla vvv
{ready}
-overwrite_original; -XPComment=bla bla bla bla vvv; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
    0 image files updated
    1 files weren't updated due to errors
{ready}
-s; -XPComment; C:\Users\ARnotAdmin\Desktop\PicsExifTest\0a.jpg; -execute
XPComment                      : bla bla bla bla vvv
{ready}
------------------------------

In the attached file, I enabled verbose mode in the overwrite.  First command was to overwrite with "" (empty string);  2nd was with some text.  It failed very quickly.

Debug (2023-03-29_1203).txt

Phil Harvey

It would help if you could report the error, but most likely this is a file access problem because the file is locked by some other software such as antivirus software.  We have seen that sort of thing a number of times in the past.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ArnieR

As a workaround, I tried placing
          Thread.Sleep(200); 
before and after the call to ExifTool to change the tag using overwrite_original.
So far, this approach seems to be working without further failures.