Avoid errors when copying files that already exist in the destination

Started by Joanna Carter, August 25, 2018, 04:50:54 AM

Previous topic - Next topic

Joanna Carter

OK. Now I get it  ::)

When I try "the" command on files that do have a DateTimeOriginal, everything is wonderful - the world is a lovely place  8)

So, obviously (?), if a file doesn't have DateTimeOriginal, it doesn't get processed at all and I get that file exists error.

The question is, having examined the EXIF in a few of those files and found they have been essentially stripped bare, is there anything I can do to conditionally fall back to the Finder date created?

Or do I just say that only files with DateTimeOriginal can be processed, or can I do a single command to detect that and set it to the Finder date/time?

Questions, questions, questions - why do I always end up doing stuff that  pushes the boundaries?  :P ::)


Joanna Carter

And the answer is, I can use the FileCreateDate tag!!!

This seems to be the same as DateTimeOriginal for RAW files, which is the primary target of this command for what I want to do.

Finally, I think we can mark this issue as solved. Many thanks for all your help.

Phil Harvey

Great.  But missing dates are a common problem, and FileCreateDate isn't always reliable, so I would suggest using it only as a fallback.  ie) doing this:

exiftool ... '-FileName<FileCreateDate' '-FileName<DateTimeOriginal' ...

Then DateTimeOriginal will get used if it exists, otherwise it will use FileCreateDate.

- 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 ($).

Joanna Carter

Interesting. So, bearing in mind the "arrow" between the date and the "directory/fileName" is from right to left, therefore the "priority" flows from right to left?

I think I'm finally getting the hang of this  8)

Joanna Carter

So, finally, here's how to create that command in my Swift wrapper:


  public static func copyAndOrganiseFilesByDate(from sourceURL: URL, to destinationURL: URL) throws
  {
    let arguments: [Argument] = [.preserveFileModificationDateTime,
                                 .recurse,
                                 .ignoreMinorErrors,
                                 .quietWarnings,
                                 .extension("jpg", exclude: false),
                                 .outputFlag,
                                 .currentDirectory,
                                 .fileNameFromTag(System.fileCreateDate),
                                 .fileNameFromTag(Exif.dateTimeOriginal),
                                 .dateFormatFlag,
                                 .fileNameWithFormat(url: destinationURL, dateFormatSpecifiers: [.year, .month, .day], fileNameFormatSpecifiers: [.fileName, .copyNumber, .lowercaseExtension]),
                                 .directory(sourceURL)]
   
    do
    {
      try execute(with: arguments)
    }
    catch
    {
      throw Error.couldNotCopyAndOrganiseFiles
    }
  }


With seems like a lot of typing but, with code completion, it's barely more than the command line  ;D

Phil Harvey

Quote from: Joanna Carter on August 27, 2018, 04:51:12 PM
Interesting. So, bearing in mind the "arrow" between the date and the "directory/fileName" is from right to left, therefore the "priority" flows from right to left?

Not quite.  In general, arguments are evaluated left to right, which does give the right argument priority, but the "arrow" may go either way: "-FileName<FileCreateDate" is the same as "-FileCreateDate>FileName"

- 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 ($).

lnjustin

When I get an 'already exists' error, is there a way to move the duplicate file to a specified directory?

Phil Harvey

No.  The thing to do is add some form of "%c" when writing the file name so that the duplicate gets a number added to it (I like "%-c" personally, to put a "-" before the number).

Then all the files will get written and you can figure out what to do with the duplicates afterwards.

- 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 ($).