2

I'm using pyrenamer with my photo collection and it works great except for one issue. I want it to rename photos by their date taken metadata, with a three-digit number at the end. Each folder in my library represents a day, and I want the photos ending in numbers from 001-999, starting with 001 for each folder. An example file name would be 2016-01-31-001.jpg.

Shotwell handles creating the directory structure on import with a %Y/%m/%d structure in the options, but when I use pyrenamer recursively in the ~/Pictures directory, I don't see the expected outcome. It renames by date but continues incrementing up across folders, instead of starting at 001 for each new folder. Is there an easier way to go about this?

I know I could add more metadata variables and rename according to hours, minutes, and seconds, but this gives longer file names than I want. My camera also can take multiple shots per second so this is problematic for renaming.

What's the easiest way to do this please? I like using pyrenamer but a bash script is fine also.

Current output:

Pictures/
├── Folder 1/
│   ├── YY-MM-DD-001.jpg
│   └── YY-MM-DD-002.jpg
├── Folder 2/
│   ├── YY-MM-DD-003.jpg
│   └── YY-MM-DD-004.jpg
...

Desired output:

Pictures/
├── Folder 1/
│   ├── YY-MM-DD-001.jpg
│   └── YY-MM-DD-002.jpg
├── Folder 2/
│   ├── YY-MM-DD-001.jpg
│   └── YY-MM-DD-002.jpg
...
  • if pyrename can't use Métamorphose file-folder-ren.sourceforge.net "Sequential numbering options include: integers, alphabetical or Roman numerals, with control over the step size, starting number and reset count". webupd8.org/2016/03/quickly-batch-rename-files-in-linux.html has a PPA – Rinzwind Mar 12 '16 at 12:25
  • and it might be a good idea to permanently switch from pyrenamer: it was abandoned in 2008 ;-) – Rinzwind Mar 12 '16 at 12:27
  • @Rinzwind I love pyrenamer for it's simplicity and speed, but I'm reading that webupd8 post and I see Metamorphose has newer code on GitHub. Maybe I'll try that instead of Sourceforge, which I generally avoid. Thanks. – Tom Brossman Mar 12 '16 at 12:37
  • What a long strange trip Métamorphose was - installing was difficult & complained of broken packages (but it did eventually run with some visual bugs). I don't think it is an option going forward though, still looking for something better. I think a bash script is going to be what I need so I'll try to create one and post an answer someday soon. – Tom Brossman Mar 12 '16 at 15:44
  • 1
    Looking at your current output / desired output it'd look like simply renaming the files in each directory (processing them in alphabetical order) starting from 001 would get you where you want (without even having to mess with exiftool). Anything wrong with this? – kos Mar 27 '16 at 14:38
3

To rename your entire image library of JPEG photos to the YYYY-MM-DD-XXX.jpg format, counting up and starting from -001 each new day, use this command with exiftool:

exiftool -fileOrder DateTimeOriginal -recurse -extension jpg -extension jpeg -ignoreMinorErrors '-FileName<CreateDate' -d %Y-%m-%d%%-.3nc.%%e ~/Pictures/

To explain the command fully, here's how it works.

  1. exiftool starts the script.
  2. -fileOrder DateTimeOriginal forces exiftool to process the images in the same order they were taken. This is critical to preserve the image numbering within a day in the original chronological order.
  3. -recurse recursively processes subdirectories, which is helpful if you use Shotwell to import because photos are placed in directories organized by date.
  4. -extension jpg -extension jpeg will make sure only JPEG files are processed. (Note these aren't case-specific and jpg=JPG so we catch everything)
  5. -ignoreMinorErrors Ignore any errors which don't affect our desired result (usually problems reading unrelated tags which aren't necessary for this operation).
  6. '-FileName<CreateDate' Puts the photo created date in the file name.
  7. -d %Y-%m-%d%%-.3nc.%%e Here -d sets the desired output date format. We'll use hyphenated four-digit year then two-digit month and day (%Y-%m-%d) followed by a three-digit number starting with 001 (%%-.3nc), preserving the original file extension (.%%e).
  8. ~/Pictures/ is the last item, it's just the directory that exiftool should process with the command.

A note about errors, the -ignoreMinorErrors helps but still you may see the message "Warning: Bad PreviewIFD directory" which is safe to ignore or "Warning: No writable tags set from /path/to/problem/image.jpg". The second one I couldn't resolve but I only saw it for a few images, so I manually renamed them in Nautilus as a workaround.

This command could still be improved but it is tested and working on a large (40GB, 13000 images) photo library and it's quick and produces no errors, only failing to rename the occasional image that is missing a tag that most any modern camera will create.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.