Renaming files using current Parent Directory in name but not rest of path

Started by chambrick, May 21, 2014, 03:16:56 PM

Previous topic - Next topic

chambrick

I'm trying to pull all photos from a directory structure with the following rules

The EXIF information will put the file in the year folder, and month folder.
Within that folder I want to name the file using the files current parent folder plus the EXIF hour,minute,second and add number if duplicate.

So:  /Users/Yoyo/Documents/whatever/x/y/coolevent/image_123.jpg  with EXIF date info of something like 12-7-11 11-12-20

would get moved to

specificpath/2012/07/coolevent-11-12-20.jpg

and if there was a duplicate the next one would be

specificpath/2012/07/coolevent-11-12-20-1.jpg

I've got this far:

exiftool  -r -d /Volumes/My\ HD/Photos\ Processed/%Y/%m/%%-.1d-%H%M%S%%-nc.%%e "-filename<alldates" /Volumes/My\ HD/Photos\ To\ Process/

The last piece of the puzzle is that it still uses the files full directory path and I can't figure out how to fix the %%-.1d regex to ignore all but the parent (or maybe worded differently use 1 level up)

Help!

Phil Harvey

This is a bit tricky, and it will take me some time to prepare an answer, but it is bed time now so it will have to wait until tomorrow.

- 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

The trick is that you want part of the directory specification in between two date/time fields.  You can't do this with the simple date/time formatting unless it can be accomplished with %d as you have tried.  But in this case, %d doesn't give you enough flexibility to extract a variable-length directory name from the path.

Instead, I will do this using the advanced formatting feature:

exiftool -r -d /Volumes/My\ HD/Photos\ Processed/%Y/%m '-filename<$datetimeoriginal/${directory;s(.*/)()}-${datetimeoriginal#;s/.* //;tr/:/-/}%-c.%e' /Volumes/My\ HD/Photos\ To\ Process/

Note that you can't use AllDates here, so you must duplicate the filename assignment using other date/time tags (in reverse order of precedence) if you want to have fallback date/time tags.

Here is an breakdown of what I am writing to FileName:

$datetimeoriginal/ - formatted date/time used for the directory specification

${directory;s(.*/)()} first part of file name is last directory in path, so delete everything up to and including the last "/".

-${datetimeoriginal#;s/.* //;tr/:/-/} - start from unformatted ("#") date/time, remove the date, then translate ":" to "-"

%-c.%e - add count if necessary, separated by a "-", and extension

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

chambrick

Awesome.  Thanks so much for your time.

Follow up question.

To compensate for the inability to use AllDates do I use the filename assignments all in one exiftool command or do I need to do separate statements?


Phil Harvey

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

chambrick

I'm finally getting back to this.

The following code:

exiftool -r -d /Volumes/Pincu\ HD/TestExif//%Y/ '-filename<$filemodifydate/${directory;s(.*/)()}—${filemodifydate#;s/.* //;tr/:/-/}%-c.%e' '-filename<$createddate/${directory;s(.*/)()}—${createddate#;s/.* //;tr/:/-/}%-c.%e' '-filename<$datetimeoriginal/${directory;s(.*/)()}—${datetimeoriginal#;s/.* //;tr/:/-/}%-c.%e' /Volumes/Pincu\ HD/TestExif/

gives me file names with Directory--hour-minute-second-plus count if necessary.extension

I need to edit the code to give me

Directory--4 digit year-month-day-hour-minute-second-plus count if necessary.extentions
or
Directory--4 digit year-month-day-hourminutesecond-plus count if necessary.extentions

whichever is easier (i'm guessing you get one you add the dashes in to the other eh)

Phil Harvey

Sure.  Everywhere in the command, change this

s/.* //;tr/:/-/

to this

tr/: /--/

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


chambrick

Phil,

You've been a wonderful help thus far so I HAD to donate.

The code from your last post was perfect...and will work with my archiving workflow.

Now I need to modify it slightly for importing into photo software...and I just can't get it right.

I'm using Hazel to move over files and this code will run on each file rather than a whole directory.

1.  So I need to pass the file name to the command and run it on a single file.

...help.

chambrick

...and then one (hopefully final) thing is that in renaming the file I'd like to put it in a new folder with the name  folder-YYYY-mm

chambrick

I thought it might be something like this:

exiftool -d '-filename<$filemodifydate/Volumes/HD/Users/Me/Desktop/ExifTesting/{directory;s(.*/)()}/' '-filename<$filemodifydate/${directory;s(.*/)()}—${filemodifydate#;tr/: /--/}%-c.%e'/Volumes/HD/Users/Me/Desktop/ExifTesting/mytestimage.jpg


(using only one of the dates to keep it simple while testing)

...but no go.

Phil Harvey

Quote from: chambrick on September 18, 2014, 07:55:09 PM
1.  So I need to pass the file name to the command and run it on a single file.

I'm not sure I understand.  Just specify the file name instead of the directory name in the exiftool command.

Quote from: chambrick on September 18, 2014, 08:22:43 PM
...and then one (hopefully final) thing is that in renaming the file I'd like to put it in a new folder with the name  folder-YYYY-mm

I'm not sure I understand.  The command moves the file to the folder specified in the command.  Do you want to change this folder?

Quote from: chambrick on September 19, 2014, 01:12:27 AM
I thought it might be something like this:

exiftool -d '-filename<$filemodifydate/Volumes/HD/Users/Me/Desktop/ExifTesting/{directory;s(.*/)()}/' '-filename<$filemodifydate/${directory;s(.*/)()}—${filemodifydate#;tr/: /--/}%-c.%e'/Volumes/HD/Users/Me/Desktop/ExifTesting/mytestimage.jpg

You forgot a date/time format string for the -d option.  Also, why are you putting FileModifyDate before "/Volumes" in the file path?  It is hard for me to help if you don't give me a specific example of the source and destination file paths that you want.

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

chambrick

That's what I get for doing stuff too late at night when exhausted.

When I CORRECTLY put the file and file path in it works.

When running the below command on an image from July 2012

exiftool -r -d /Volumes/HSI-HD/Users/Me/Desktop/ExifTesting/MyEvent//%Y/ '-filename<$filemodifydate/${directory;s(.*/)()}—${filemodifydate#;tr/: /--/}%-c.%e' '-filename<$createdate/${directory;s(.*/)()}—${createdate#;tr/: /--/}%-c.%e' '-filename<$datetimeoriginal/${directory;s(.*/)()}—${datetimeoriginal#;tr/: /--/}%-c.%e' /Volumes/HSI-HD/Users/Me/Desktop/ExifTesting/MyEvent/temp.jpg

Renames the file correctly and puts it in /Volumes/HSI-HD/Users/Me/Desktop/ExifTesting/MyEvent/2012

Now I'd like to change the code to put it in /Volumes/HSI-HD/Users/Me/Desktop/ExifTesting/MyEvent-2012-07

Phil Harvey

OK then, change the -d option to this:

-d /Volumes/HSI-HD/Users/Me/Desktop/ExifTesting/MyEvent-%Y-%m/

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