Renaming and Organizing scripts (Apple script?)

Started by Einho, October 15, 2015, 04:21:45 AM

Previous topic - Next topic

Einho

Hello,

I'm pretty new to ExifTool and have had a bit of hard time to get it to work.

Situation: I recently lost terabytes of raw and jpeg because of a Raid storage malfunction, and hopefully recovered most of them, but because they were on a mac managed storage, filenames and folders structures aren't recovered.
The good news is that I still have the folder structure on Lightroom, so I can reconstruct manually I guess, but sadly, as I always keep original (camera) filenames, I'll have to rename and move around 200K++ photos and videos.

So here is what I want to do:
1) Moving these tens of thousands picture into directories based simply on their shooting date
2) Rename each file to its original in-camera name.

I tested the following commands:
1) (In ExifTool GUI) exiftool '-Directory<CreateDate' -d %y%m%d
2) (In each directory, Terminal) exiftool "-filename<IMG_${fileindex}.%e" .

The first moved the images to the correct folder name ... but ended also moving the pictures from the storage disk to the desktop where ExifTool GUI was, so I stopped using it.
The second seemed to work correctly only on raws and some jpeg (it seems anything modified with Photoshop/Lightroom lost the fileindex field) ... Also, images bellow 1000 ignored the 0 (ending with IMG_2, IMG_37 and IMG_456, etc)


The question/request:
Is there any way to have a simpler script (terminal or applescript) that does the following:
-> Checks the photo/video and see if it has both CreateDate and FileIndex fields
-> If yes, move the file to "yyyymmdd" folder (same directory where all recovered photos are) AND rename to IMG_XXXX
-> If not, move them to "NoName/yyyymmdd" folder without renaming

BTW: What is the difference between FileIndex and FileIndex2 ? ... Sometimes they are in sync, sometimes not.


Thank you for the help.

Phil Harvey

Quote from: Einho on October 15, 2015, 04:21:45 AM
Is there any way to have a simpler script (terminal or applescript) that does the following:
-> Checks the photo/video and see if it has both CreateDate and FileIndex fields
-> If yes, move the file to "yyyymmdd" folder (same directory where all recovered photos are) AND rename to IMG_XXXX
-> If not, move them to "NoName/yyyymmdd" folder without renaming

Try this:

exiftool '-filename<${directory}NoName/$createdate/%f.%e' '-filename<$directory$createdate/IMG_${fileindex;$_=sprintf("%.4d",$_)}.%e' -d %Y%m%d DIR

Tip:  First try this command using TestName instead of FileName to see if it works before actually moving/renaming the files.

Quote
BTW: What is the difference between FileIndex and FileIndex2 ? ... Sometimes they are in sync, sometimes not.

No idea.  There is a lot of redundant information in many images, and it is difficult to decode it all fully.  If you can figure out the difference for your camera, please let me know.

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

Einho

Dear Phil,

Thank you for your answer, the script works like a charm for most parts.

I changed only one thing in the code, I added a slash between $directory and the rest:
exiftool '-filename<${directory}/NoName/$createdate/%f.%e' '-filename<$directory/$createdate/IMG_${fileindex;$_=sprintf("%.4d",$_)}.%e' -d %Y%m%d [b]/Volumes/External/recovered/[/b]

sadly, the script got some hiccups exactly where I was worried of: FileIndex

I first thought that "FileIndex" was the real name in-camera, and "maybe" that FileIndex2 was the sequence number on card (when we delete pictures, and the camera still displays a logical numbering xxx/yyyy).
But that wasn't the case ... I've got some folders (or pictures from the same day sometimes), where ALL pictures have exactly the same FileIndex ... So the script (hopefully) failed as the filename existed.
(BTW, is there any safeguard to unsure no file is overwritten?)

Here is the result of check commands:
$ exiftool -canon:fileindex Conflict0.CR2
File Index                      : 6726
$ exiftool -canon:fileindex Conflict1.CR2
File Index                      : 6726
$ exiftool -canon:fileindex Conflict2.CR2
File Index                      : 6726
$ exiftool -canon:fileindex Conflict3.CR2
File Index                      : 6726
$ exiftool -canon:fileindex Conflict4.CR2
File Index                      : 6726

$ exiftool -canon:fileindex2 Conflict0.CR2
File Index 2                    : 6739
$ exiftool -canon:fileindex2 Conflict1.CR2
File Index 2                    : 6741
$ exiftool -canon:fileindex2 Conflict2.CR2
File Index 2                    : 6742
$ exiftool -canon:fileindex2 Conflict3.CR2
File Index 2                    : 6743
$ exiftool -canon:fileindex2 Conflict4.CR2
File Index 2                    : 6744


I would like to enhance the script now and wonder if you can help:
1) If no FileIndex or no FileIndex2: Move to Noname/CreatedDate
2) If (FileIndex != FileIndex2): Move to Conflict/CreatedDate                                     (the new step)
3) If (FileIndex == FileIndex2): Move to CreateDate and rename to IMG_$FileIndex    (same until now, just checking that FileIndex2 exists and equals FileIndex)


Thank you very much for excellent work and help.

Phil Harvey

Quote from: Einho on October 16, 2015, 12:20:39 AM
I changed only one thing in the code, I added a slash between $directory and the rest:

Right.  I forgot that the Directory tag doesn't include the trailing "/" (but %d does).

Quote(BTW, is there any safeguard to unsure no file is overwritten?)

You don't need to worry.  ExifTool will never overwrite an existing image file.

QuoteI would like to enhance the script now and wonder if you can help:
1) If no FileIndex or no FileIndex2: Move to Noname/CreatedDate
2) If (FileIndex != FileIndex2): Move to Conflict/CreatedDate                                     (the new step)
3) If (FileIndex == FileIndex2): Move to CreateDate and rename to IMG_$FileIndex    (same until now, just checking that FileIndex2 exists and equals FileIndex)

Run this command before the other:

exiftool -if '$fileIndex and $fileindex2 and $fileindex != $fileindex2' '-filename<${directory}/Conflict/$createdate/%f.%e'

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

Einho

Dear Phil,

Thank you for your answer.

The scripts worked as expected, that was a huge life saver.
Sadly, the data didn't always work as expected ... I thought it was a problem from the recovery process, but then tested with newly shot pictures and some downloaded from the internet:
- I still have no idea what FileIndex2 is for ... It works fine on some shots, then freezes for few thousands, then works okay again.
- There is no fileindex or such on videos nor on the JPEGs, especially on older models.
- The same goes for photos and videos from smartphones (I shoot rarely on those, so wasn't a problem for me)
- If one doesn't have a very well organised library, it's a real hell to get it back (for example having a "2015-04 divers" folder along with more specific "2015-04-XX YYY").

For the videos, I ended up looking into lightroom by date (as DateCreated was the only usable exif field) to find out their name and which directory they belong to ... Nearly finished, a couple thousands extra and it's done.

Quote from: Phil Harvey on October 16, 2015, 07:17:42 AM
You don't need to worry.  ExifTool will never overwrite an existing image file.

Thank you, a life saver.


In regards to my suffering, I'm looking up to make an open-source program for photographers in order to match their Lightroom library and photos on a disk (recovery, moved/renamed files, external drives sync, etc) by using exif information (createdate, camera, size, duration, etc).
Will post it here when done.

Thank you very much.