View previous topic :: View next topic |
Author |
Message |
haneulso Apprentice
Joined: 31 Aug 2004 Posts: 173
|
Posted: Mon Sep 24, 2018 12:30 pm Post subject: exiftool how to? |
|
|
I want to rename some jpg images file which were took by digital camera.
The work is
1. use exiftool to rename jpg file with exif information like 20180512-125637.jpg.
2. and move that renamed file to new directory made by exif information like 201805.
Is it possible? |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Mon Sep 24, 2018 1:14 pm Post subject: |
|
|
I do something like this routinely. Tonight when I'm home I can post my script here, if you'd like. I have over a decade's worth of photos stored by date, this way. _________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Mon Sep 24, 2018 2:15 pm Post subject: Re: exiftool how to? |
|
|
haneulso wrote: | 1. use exiftool to rename jpg file with exif information like 20180512-125637.jpg.
2. and move that renamed file to new directory made by exif information like 201805. |
haneulso ... everything is possible ... with the right shell:
Code: | % echo $SHELL
/bin/zsh
% for n in {1..4}; do cp ~/file.jpg $n.jpg ; done
% ls
1.jpg 2.jpg 3.jpg 4.jpg
% i=0 ; for f (*.jpg) zmv $f $(exiftool -s3 -d '%Y%M%d' '-EXIF:CreateDate' $f)-'${(l:6::0:)$((++i))}'.jpg
mv -- 1.jpg 20130416-000001.jpg
mv -- 2.jpg 20130416-000002.jpg
mv -- 3.jpg 20130416-000003.jpg
mv -- 4.jpg 20130416-000004.jpg |
... but that's probably not what you're looking for.
EDIT: forgot question 2, move to a new directory based on date ... that's doable too, but I'll leave it as an excercise (given you're probably not going to use zsh) ... or ask.
best ... khay |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21639
|
Posted: Tue Sep 25, 2018 1:37 am Post subject: |
|
|
Assuming that . has the files generated in step 1, and that you want them moved to subdirectories under ., and that there are sufficiently few files that a shell glob is viable: Code: | for f in *.jpg; do mv "$f" "${f:0:6}/"; done | If you need the directory created automatically, add before mv: mkdir -p "${f:0:6}". -p is meant for creating multiple levels, but has the nice side effect that trying to create a directory which already exists does not print an error. This allows you to wastefully attempt the creation on every pass, instead of needing a preparatory phase to create the directory once. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Tue Sep 25, 2018 8:17 am Post subject: |
|
|
Hu wrote: | Code: | for f in *.jpg; do mv "$f" "${f:0:6}/"; done |
|
Hu ... I had in mind to do the whole thing in one step, eg:
Code: | % echo $SHELL
/bin/zsh
% i=0 ; for f in *.jpg ; do fn=$(exiftool -s3 -d '%Y%M%d' '-EXIF:CreateDate' $f) ; mkdir -p ${fn:0:6} ; zmv $f ${fn:0:6}/${fn}-'${(l:6::0:)$((++i))}'.jpg ; done
mv -- 1.jpg 201304/20130416-000001.jpg
mv -- 2.jpg 201304/20130416-000002.jpg
mv -- 3.jpg 201304/20130416-000003.jpg
mv -- 4.jpg 201304/20130416-000004.jpg |
There is probably a way to do that in bash, but not as easily or succinctly.
edit to add: don't really need the 'zmv' there, 'mv' would work just as well, I only used it to provide the output.
best ... khay |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Tue Sep 25, 2018 1:45 pm Post subject: |
|
|
khayyam wrote: | There is probably a way to do that in bash, but not as easily or succinctly. |
Here's a go in bash:
Code: | $ i=1 ; for f in *.jpg ; do fn=$(exiftool -s3 -d '%Y%M%d' '-EXIF:CreateDate' "$f") ; mkdir -p ${fn:0:6} ; mv $f ${fn:0:6}/${fn}-$(printf "%06d.jpg" $i) ; ((i++)) ; done
$ ls 201304/
20130416-000001.jpg 20130416-000002.jpg 20130416-000003.jpg 20130416-000004.jpg |
best ... khay |
|
Back to top |
|
|
|