delete files if destination already exists

Started by mileno, December 06, 2021, 08:05:46 AM

Previous topic - Next topic

mileno

Hi all,

if have a script to extract create date-time from a image-file and then rename this file with the create-date and move it to another folder.
Sometimes it happens that the destination file already exists because the source file was imported again by a script.
exiftools throws then an error "file already exists" and skip moving this file.

What I want is that in this case the original file should be deleted or moved to a trash folder to avoid it staying for ever in den source folder.

Is there a way to tell exiftool to delete the original file if the destination file already exists during a operation?

My script looks like this:
/usr/share/applications/ExifTool/exiftool '-Filename<FileInodeChangeDate' -d /DESTINATION_DIR/%Y/%Y-%m/IMG_%Y-%m-%d_%H%M%S.%%le  /SOURCE_DIR  -ext JPG JPEG PNG

Thanks in advance,

Phil Harvey

ExifTool can not be used to simply delete a file.  Why don't you just move all the remaining files out of SOURCE_DIR after running ExifTool?  (Then delete them later if you want.)

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

mileno

Hi Phil,

thank you very much for your quick reply - and this wonderful tool.

My issue is that i don't want to delete all files after running exiftool, because sometimes exiftool cannot get metadata (e.g. from video files etc.). So I would be able to process these files manually afterwards.
I only want to delete the files that has been registered as already existing in the destination folder.
Is it possible to change the filename of the original file in case the destination file already exists, so I can use this marker afterwards to move these files?

Thanks in advance.
Mil

Phil Harvey

Hi Mil,

In your example command, FileInodeChangeDate should always exist, so the command should only fail if the destination file already exists.  But I guess you are using a different command in your workflow.

You could do something like this:

-d /DESTINATION_DIR/%Y/%Y-%m/IMG_%Y-%m-%d_%H%M%S.%%le%%-10c

Then the file would always be moved, but a 10-digit suffix with leading "-" will be added if the file already exists.  It should be easy to find these files.

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