Conduct only one file per folder with -r ?

Started by Luuk2005, October 30, 2020, 11:20:14 AM

Previous topic - Next topic

Luuk2005

Greetings to the experts!
Martin is having 2000+ folders with filenames trailing like SameText_###.jpg, but likes to change _Highest### --> _999_okladka.
For better explanation, please to see... www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=5201.. The best I can invent is like this...exiftool -q -ext jpg -Fast4 -FileOrder -FileName -if "$FileSequence==0 and $Filename =~ /_\d{3}\.(?i)jpe?g$$/" -TESTname"<${filename;s/(.*_)\d+(.*)/$1\999_okladka$2/}" .

This so that if folder has names like zzz.jpg, then file must not be renamed, its working but only for just one folder. In trying many experiments with -r and . the $FileSequence not resets per folder, and always wants to be read-only, so Im putting the exiftool in a For-Loop, this works but makes it very slow to stop and start for each folder!

Is there better ways to conduct only the file with highest### per folder, while using the -r in Windows?
Thanks much in advance!
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

StarGeek

I was about to say it would be easier to do it the way suggested in some of those other posts, then I noticed you had put -FileOrder -FileName in there.  Very smart.  The equivalent of Tail 1 as suggested in that thread.  All you need now is to figure out the EndDir() function.  See under the -if option and search on these forums.  I haven't taken time to figure it out myself, so I can't really help but I think you may only need to add and EndDir() to the -if statement.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Luuk2005

Very many thanks StarGeek!
This EndDir() is to be very useful, but -FileOrder seems to be prejudice against it and overrides?
exiftool -q -r -ext jpg -FileOrder -FileName -if "$Filename =~ /_\d{3}\.(?i)jpe?g$$/ and EndDir()" -TESTname"<${filename;s/(.*_)\d+(.*)/$1\999$2/}" .

'./bb/b39_1642_0_0_88_012.jpg' --> './bb/b39_1642_0_0_88_999.jpg'
Warning: File './bb/b39_1642_0_0_88_999.jpg' would exist - ./bb/b39_1642_0_0_88_011.jpg
Warning: File './bb/b39_1642_0_0_88_999.jpg' would exist - ./bb/b39_1642_0_0_88_010.jpg
Warning: File './bb/b39_1642_0_0_88_999.jpg' would exist - ./bb/.............................._009.jpg
Warning: File './bb/b39_1642_0_0_88_999.jpg' would exist - ./bb/..............................._etc.jpg


So then I remove '-FileOrder AnyTagName', and EndDir() conducts with 1st-filename match!

exiftool -q -r -ext jpg -if "$Filename =~ /_\d{3}\.(?i)jpe?g$$/ and EndDir()" -TESTname"<${filename;s/(.*_)\d+(.*)/$1\999$2/}" .

'./bb/b39_1642_0_0_88_001.jpg' --> './bb/b39_1642_0_0_88_999
EndDir called - ./bb/b39_1642_0_0_88_001.jpg

Can it be true that EndDir() and -FileOrder is not compatible??
Lucky Im thinking it not matters in this case, except for the speed.. Because if all files are SameText_### anyway, then -r is not be a problem, since s/// just creates duplicate name and were not using the %c anyway.. Thanks again!
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

StarGeek

Quote from: Luuk2005 on October 30, 2020, 02:40:18 PM
Can it be true that EndDir() and -FileOrder is not compatible??

I think Phil will have to check on this.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Luuk2005

Its not to be priority, because already there is the slower solution. Even if its a few minutes, this is still many worlds better than the other ways so far. But its unfortunate I make the title 'Conduct only one file per folder', because really it should say 'Conduct only the last Name_### per folder' but Im not seeing the way to change it.
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

Phil Harvey

Right.  EndDIr() doesn't currently work with -fileorder.  I'll see about fixing this.  Thanks for pointing this out.

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

Phil Harvey

#6
Ooops.  This can't be fixed.

I should have thought of this:  The -fileOrder option spans directories, so the EndDir() has no meaning when applied to the result of -fileOrder (ie. the files are processed in the sort order, and not by directories).

I will document this.

- Phil

Edit:  Maybe there is hope.  I just thought of a way this could work.  I'll look into it.  I think this may be a useful change if I can do it.
...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 ($).

Phil Harvey

I've patched ExifTool 12.11 (to be release probably next week) so the EndDir() function will work in combination with -fileOrder.

It will also now work if files are specified separately on the command line.  eg)

exiftool -fileorder filename -if "$filename eq 'b.jpg' and EndDir(); 1" dir2/d.jpg dir1/c.jpg dir1/a.jpg dir1/b.jpg

Will process dir1/a.jpg, dir1/b.jpg and dir2/d.jpg, in that order.

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