Complex (to me) renaming & moving structure

Started by GoodKarma, October 18, 2021, 10:21:01 AM

Previous topic - Next topic

GoodKarma

Hi, Thanks to all that that have worked on this powerful tool.

I am using Ubuntu 18.04 LTS

I have the following folder structure;


bracketing
[100789,100780,100781] These are sub-directories

These files are within sub-directory 100789

10000787.dng 10000787.jpg
10000788.dng 10000788jpg
10000789.dng 10000789.jpg

sub-directory 100780 and 100781 all have similar named files.

What I'd like to do if possible is rename the files, giving the matching pairs of of dng and jpeg the same sequence number if possible?

so they are renamed as follows;

10000787_0001.dng 10000787_0001.jpg
10000788_0002.dng 10000788_0002jpg
10000789_0003.dng 10000789._0003jpg

Heres what i Have done

exiftool -d '%Y%m%d_%H%M%S.%%e' '-filename<CreateDate' 100007*

which renamed the all files as I want but without the sequence number. I tried adding %%4nc (after reading some documentation but it gave an error)

I'd like to do this on all sub directories within the bracketing folder

Id then like to separate the images into subfolders based on ext, so

100789
    JPG
    DNG

100790
    JPG
    DNG

I used the following command
exiftool -r %d bracketing/ -directory=%e

which moved every single file within subfolders inside the bracketing folder to 2 new directories, so I then have the following folders. I did try some variations on this code to no avail

Bracketing ( existing folder)
JPG
DNG

not what i intended

I did try a variation of example 6

exiftool -r -d %Y/%m/%d/image_%H%M%S.%%e "-filename<filemodifydate" DIR

however i somehow got it to just print the exif data from all the files

Any help and.or criticism will be hugely appreciated

StarGeek

Offhand, I can't think of an easy way to do this.  The addition of the file sequence number is the problem.  Exiftool can only process and rename one file at a time and every new file will increment the counter.

As long as you know there will always be a matching file, you could run two separate commands to add the sequence number, once for the DNGs and once for the jpgs.  Otherwise the numbers would be off.

exiftool -fileorder Filename -ext DNG -d '%Y%m%d_%H%M%S_%%.4nC.%%e' '-filename<CreateDate' /path/to/files/
exiftool -fileorder Filename -ext jpg -d '%Y%m%d_%H%M%S_%%.4nC.%%e' '-filename<CreateDate' /path/to/files/

Alternatively, you could use embed a count number in some rarely used tag using the FileSequence tag, then use the -TagsFromFile option to copy that embedded number to the filename

Example using the rarely used Creative Commons tag AttributionName. First embed in the jpgs, since most people don't like to touch their raws.  FileSequence normally starts at 0 so this will increment the value to start at 1.  I'm also including the -FileOrder option just in case the file names are not alphabetical when exiftool receives them.  It's unlikely but better safe than sorry in this case.
exiftool -Fileorder Filename -ext jpg '-AttributionName<${FileSequence;$_+=1}' /path/to/files/

Then you use -TagsFromFile to copy from AttributionName.  DNG files must be handled first, so -FileOrder is used again to make sure of that.
exiftool -FileOrder Filename -d '%Y%m%d_%H%M%S' -TagsFromFile %d%f.jpg  '-filename<$CreateDate_$AttributionName.%e' /path/to/files/

You could then remove the AttributionName tag
exiftool -ext jpg -AttributionName= /path/to/files/

Of course, test this first and don't run on multiple directories at once unless you want the file count to span the multiple directories.
"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

GoodKarma

Thank you StarGeek for a very detailed and speedy reply, the first option has worked perfectly on my drone files. I also tested on multiple directories and its all good thanks, however I'm still struggling to move all the files into folders based on extension within their initial folder, so we have;

10000745
DNG  (inside 10000745)
JPG    (inside 10000745)

10000746
DNG  (inside 10000746)
JPG    (inside 10000746)

What I am doing(wrongly) is creating them outside of the folder 10000745 and10000746 respectively


StarGeek

Try changing this
-d '%Y%m%d_%H%M%S_%%.4nC.%%e'
into
-d '%%d/DNG/%Y%m%d_%H%M%S_%%.4nC.%%e'
and
-d '%%d/JPG/%Y%m%d_%H%M%S_%%.4nC.%%e'

Test it out first, of course. You can change FileName into TestName and exiftool will tell you what it would have renamed the files to.
"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

GoodKarma

Outstanding StarGeek, worked an absolute treat, thanks for your help and time