Recursive %-C not restarting copy number in sub directories

Started by strwrsdbz, January 16, 2021, 03:54:21 PM

Previous topic - Next topic

strwrsdbz

Hi

I'll try to explain what my goal is and what I have so far, since there's a good chance I'm making things more complicated than they need to be. My OS is 64-bit Fedora 32 with exiftool version 12.00.

I want to create directories with the CreateDate year that hold sub-directories named YYYY-MM-DD-event. The sub-directories will hold multiple images from the same day and event, with a copy number at the end, sorted by CreateDate. I can get very close with this

exiftool -ignoreMinorErrors -recurse -fileOrder CreateDate '-FileName<$CreateDate.$FileTypeExtension' -dateFormat /path/to/Pictures/storage/%Y/%Y-%m-%d-%%-1:D/%Y-%m-%d-%%-1:D-%%.3nc /path/to/Pictures/staging/

but files within the sub-directories with different extensions "restart" the copy number (e.g. there would be 2020-07-15-birthday-01.jpg and 2020-07-15-birthday-01.png instead of 2020-07-15-birthday-01.jpg and 2020-07-15-birthday-02.png). I want the copy number to increment across different extensions so each number is unique and comes from the time within that day.

It seems like I would need to do two passes to make this work. One that sets up the year directories with the sub-directories. Then a second pass that uses %-C (capital version) so the numbers do not restart. From what the docs say currently, the "-" should reset the copy number in each new directory. I have tried this

exiftool -ignoreMinorErrors -recurse '-FileName<$CreateDate.$FileTypeExtension' -dateFormat /path/to/Pictures/storage/tmp/%Y/%Y-%m-%d-%%-1:D/%Y-%m-%d-%%-1:D-%%-.4C /path/to/Pictures/staging

which gives something like this

storage
└── tmp
    └── 2019
        ├── 2019-08-31-trip
        │   └── 2019-08-31-trip-0089.jpg
        ├── 2019-09-01-trip
        │   ├── 2019-09-01-trip-0004.jpg
        │   ├── 2019-09-01-trip-0015.jpg
        │   └── 2019-09-01-trip-0120.jpg
        ├── 2019-09-04-Bologna-Italy
        │   ├── 2019-09-04-trip-0026.heic
        │   ├── 2019-09-04-trip-0066.heic
        │   ├── 2019-09-04-trip-0074.jpg
        │   └── 2019-09-04-trip-0091.heic
.
.
.

followed by

exiftool -ignoreMinorErrors -recurse -fileOrder CreateDate '-FileName<$CreateDate.$FileTypeExtension' -dateFormat /path/to/Pictures/storage/%Y/%%-1:D/%%-.5f-%%-.3nC /path/to/Pictures/storage/tmp

but the copy numbers do not restart in each sub-directory (below)

storage
├── 2019
│   ├── 2019-08-31-trip
│   │   └── 2019-08-31-trip-001.jpg
│   ├── 2019-09-01-trip
│   │   ├── 2019-09-01-trip-002.jpg
│   │   ├── 2019-09-01-trip-003.jpg
│   │   └── 2019-09-01-trip-004.jpg
│   ├── 2019-09-04-Bologna-Italy
│   │   ├── 2019-09-04-trip-007.heic
│   │   ├── 2019-09-04-trip-008.heic
│   │   ├── 2019-09-04-trip-009.heic
│   │   └── 2019-09-04-trip-010.jpg

Sorry for the novel-length post and thanks for any suggestions.

Luuk2005

Greetings, I was having a very similiar problem, because the -FileOrder is being prejudice against directory order.
With me it was trying to use EndDir(), so this not exact solution, but try experiments without -fileorder like...
exiftool -m -r -TESTName'<$CreateDate.$FileTypeExtension' -d '/tmp/%Y/%Y-%m-%d-%%-1:D/%Y-%m-%d-%%-1:D-%%-.4nc'  /path/to/Pictures
If the flenames present satisfactory, then it can be safe changing TESTName into FileName.

What Im wishing for is -sort option, like -SortBy TagName that not overrides directory order (like the way filename is now default sort).
Im thinking your only way is use -execute that includes seconds or more to make for the proper sorting, then another like above to remove the seconds.
Windows8.1-64bit, exiftool-v12.11(standalone), sed-v4.0.7

Luuk2005

Sorry for the poor explanations.. This maybe is better description with example outputs, but not the only way....
First is moving to folders with names in proper sort for next command...
exiftool -m -r -ext jpg -FILEName'<$FileCreateDate.$FileTypeExtension' -d '/tmp/%Y/%Y-%m-%d-%%-1:D/%s-%%-.3nC'  'C:/SomePath/'

C:/SomePath/Dir1/aaa.jpg ---> /tmp/2002/2002-02-02-Dir1/1012691366-001.jpg
C:/SomePath/Dir2/bbb.jpg' --> /tmp/2009/2009-02-18-Dir2/1234945329-002.jpg

Then experiment to see the better names (with -0001 as suffix for earliest file in each folder)...
exiftool -m -r -ext jpg -TESTName'<${FileCreateDate}.$FileTypeExtension -d '%%-1:D-%%-.4nC' 'C:/tmp/'

C:/tmp/2021/2021-01-06-Dir5/1609966472-###.jpg --> C:/tmp/2021/2021-01-06-Dir5/2021-01-06-Dir5-0001.jpg

After the experiments, you can join them on one line with -execute, if its to be preferred.
Windows8.1-64bit, exiftool-v12.11(standalone), sed-v4.0.7

Phil Harvey

Yes, the -fileOrder option effectively removes the directory barriers.  I need to think about this, but I don't see an easy way around it at the moment.

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

strwrsdbz

Thanks for the explanations and suggestions. I hadn't thought of using the time as an intermediate file name to get the correct order, and then renaming the files with copy numbers after that. For now I've decided to do that second step in Python (I already had a wrapper script that was doing some file verification so it's just a part of that now). I guess it's a bit lazy on the exiftool side, on my part, but a bit quicker/simpler for me to whip together for now.

Maybe I'll revisit getting this all done with exiftool if the fileorder and copy number interaction is changed. Thanks again.