Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
exiftool how to?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
haneulso
Apprentice
Apprentice


Joined: 31 Aug 2004
Posts: 173

PostPosted: Mon Sep 24, 2018 12:30 pm    Post subject: exiftool how to? Reply with quote

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
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3509

PostPosted: Mon Sep 24, 2018 1:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Mon Sep 24, 2018 2:15 pm    Post subject: Re: exiftool how to? Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21489

PostPosted: Tue Sep 25, 2018 1:37 am    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Tue Sep 25, 2018 8:17 am    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Tue Sep 25, 2018 1:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum