0

Trying to switch to Exiftool from jhead to rename more filetypes other than jpg & jpeg.

Whats the script for exiftool to convert from jhead:

jhead -n"%Y_%m_%d-newname-%04i" *.jpg

output: 2019_10_05-newname-0001.jpg

*.jpg as multiple files

jcron13
  • 17
  • 4

1 Answers1

0

Jhead's -n option appears to read the DateTimeOriginal tag for the timestamp so you would be doing a tag copy from DateTimeOriginal to Filename. You would use the -d (dateFormat) option to format the timestamp to your pattern and exiftool uses about the same format as JHead (see here for exiftool date formatting variables).

Exiftool has the FileSequence tag that will holds the file count. In order to pad that out to four places, you have to use the Advanced formatting feature and a bit of perl code.

The end result would be something like this:
Windows: exiftool -d "%Y_%m_%d" "-Filename<${DateTimeOriginal}-newname-${FileSequence;$_=sprintf('%04d', $_ )}.%e" <FilesOrDirs>

Mac/Linux: exiftool -d '%Y_%m_%d' '-Filename<${DateTimeOriginal}-newname-${FileSequence;$_=sprintf("%04d", $_ )}.%e' <FilesOrDirs>

Replace Filename with Testname to test the command without actually renaming any files. Swap single/double quotes if running Mac/Linux to avoid bash interpreting parts of the command as variables. Add -r (recurse) option to recurse into subdirectories.

StarGeek
  • 3,803
  • 11
  • 21
  • Thankyou, I tried your script and used the Testname on a jpg file, output gave: “Warning: syntax error for ‘FileSequence’ - /Dir/.../.../image.jpg” - “/Users/name/Desktop/Folder’ —> ‘2010_04_25-Newname-12.jpg” – jcron13 Nov 06 '19 at 04:15
  • Using MacOS, I also changed the quotes from double to single. – jcron13 Nov 06 '19 at 04:29
  • Swap all quotes. Change all single quotes to double and all double quotes to single. Make sure you're not using Fancy Quotes ❝ ❞ ❛ ❜ because some macs are set up to automatically "help" by changing regular quotes into fancy quotes. – StarGeek Nov 06 '19 at 18:31
  • Thanks It worked, I edited your original comment to include MacOS. – jcron13 Nov 06 '19 at 21:57
  • Now Im renaming a MP4 file, it gave an error output: Warning: [minor] The ExtractEmbedded option may find more tags in the movie data - /User/name/Pictures/Videos/Vid001.MP4 Warning: No writable tags set from /User/name/Pictures/Videos/Vid001.MP4 – jcron13 Nov 06 '19 at 22:20
  • Video files use different tags compared to image files. I'd suggest using CreateDate for those. If that doesn't work, run exiftool -s FILE.mp4 to see the tags in the file and pick one that would work for you. – StarGeek Nov 06 '19 at 22:48
  • Regarding quotes in Windows cmd shell, see: Escape double quotes in parameter ([so]) – scottbb Nov 07 '19 at 03:06
  • @StarGeek I used TrackCreateDate and it worked :-) Thanks – jcron13 Nov 07 '19 at 06:41
  • Hi @StarGeek , This is off topic to this particular question, but I’ll remove once answered. I’m having problems with the Jhead tool, the output of renaming includes quotation marks like this “2003_05_23-foobar-0007”.jpg using this command jhead -n"%Y_%m_%d-newname-%04i" *.jpg .It has worked fine a couple weeks ago, I’m not sure whats causing this. Can Exiftool replace quotation marks by removing it for affected files. Also Exiftool is unable to find the Directory of a folder when executing the command shown in this post. I’m thinking macOS file permissions is causing it from a recent update – jcron13 Jul 17 '20 at 11:56
  • Make sure you're using regular quotes in your command. Your example filename has Fancy Quotes/Smart Quotes (see here). Try this to remove them with exiftool exiftool -r '-Filename<${Filename;s/“|”//g}' /path/to/files/ Make sure the quotes don't get replaced with the Smart Quotes when you type that in. – StarGeek Jul 17 '20 at 15:22
  • I’ll try again, I did copy and pasted it into Terminal before. Thanks. – jcron13 Jul 18 '20 at 00:32