How add a number at the end of a File Name when sorting by year?

Started by distante, January 14, 2024, 04:02:08 PM

Previous topic - Next topic

distante

Hello!

I have found this really cool library and I am using it to try to sort a lot of photos I have into YEAR folders,

exiftool -m -r -Directory=/Users/me/test/NO_METADATA "-Directory<DateTimeOriginal" -d "/Users/me/test/SORTED/%Y" "./test/my-folder"

The problem I have is that when a file with the same name already exists (probably because it is duplicated really), the process ends with an error.

Is there a way to say "please add an `-1`, `-2`, and so on if the file already exists?

I am running yet another script to handle the `NO_METADATA` images and it is not called because the `exifool` command throws and I would not like to catch those errors since they point me to things I need to fix.

Thank you in advance and thank you for this wonderful tool!

StarGeek

Because you want to change the filename, instead of using Diretory, you have to use Filename and add the %c variable.

exiftool -m -r -Directory=/Users/me/test/NO_METADATA "-Filename<$DateTimeOriginal/%f%-c.%e" -d "/Users/me/test/SORTED/%Y" "./test/my-folder"

See the -w (-TextOut) option for details on the percent variables and the Writing "FileName" and "Directory" tags page for more information.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

distante

Hi thanks for the response.

Using that code complains about the <.
QuoteWarning: Invalid tag name '/%f%-c.%e'. Use '=' not '<' to assign a tag value - ./test/21.07.16/Retrica/IMG_20160607_101242526.jpg

Changing the < to = puts everything on the NO_METADATA folder.

I changed it in this way and it worked (unless I am missing something):

exiftool -m -r -Directory=/Users/me/test/NO_METADATA "-Directory<DateTimeOriginal" "-Filename=${sortedFolder}/%Y/%f%-c.%e" -d "/Users/me/test/SORTED/%Y" "./test/my-folder"

Phil Harvey

You haven't told us which command shell you are using, but it appears you need to use single quotes not double quotes.  See my signature.

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

distante

Quote from: Phil Harvey on January 15, 2024, 08:08:28 AMYou haven't told us which command shell you are using, but it appears you need to use single quotes not double quotes.  See my signature.

- Phil

Ah sorry, I am using a mix of the Terminal in Mac for single testing and a NodeJs script to process the folder I give dynamically.

At the end, in the NODEJS script, it is called in this way:

function sortFolderWithExiftool(sourceFolderPath: string) {
  const destinationFolder = path.join(cwd(), 'test');
  const unsortedFolder = path.join(destinationFolder, 'NO_METADATA');
  const sortedFolder = path.join(destinationFolder, 'SORTED');
  // see: https://exiftool.org/forum/index.php?topic=15580.msg83710#msg83710
  execSync(`exiftool -m -r -Directory=${unsortedFolder} "-Directory<DateTimeOriginal" "-Filename=${sortedFolder}/%Y/%f%-c.%e" -d "${sortedFolder}/%Y" "${sourceFolderPath}"`, {stdio:'inherit'})
}



But like I said, unless I am missing something. I think it is now working as I expected it.  :)