LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-24-2007, 01:06 AM   #1
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Rep: Reputation: 31
bash code to recursively remove EXIF info


Hi,

I am trying to write a small program to automate my EXIF extraction and rotation for my images. My images are organized as:

year/month/date

And I would like to be able to call this script from any level in the tree. The idea is to call jhead everywhere to rotate and then to remove the EXIF info before proceeding to the next level.

My current program only goes one level in the tree. And I still dont understand why it doenst work. Can anyone tell me what I need to do to go from year and get to all my months, day by day? This script can go from the month and modify each day but that is all.

Here it goes:
Code:
#!/bin/bash

olddir=$PWD

processDir(){


        cd "$olddir/$1"
        echo "I am in $1"
        ls
        jhead -autorot -purejpg -exonly *.JPG

}

for dir in */
do
        echo "Dir is $dir"
        processDir "$1/$dir"
done

cd "$olddir"
Thank you for any suggestions.

--EDITED---
Actually, After I posted this I saw that my program simply doesnt recurse. So, now, all I need to do is to figure out how to add the processDir call in the processDir function to do what I want.

Last edited by leosgb; 10-24-2007 at 01:15 AM.
 
Old 10-24-2007, 01:58 AM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
You dont need a recursive function to do that.
just find the list list of all jpeg files and use the command on the list.


#!/bin/bash
FILE_LIST=`find . -iname "*.jpg"`
for EACH_FILE in $FILE_LIST
do
echo "The file is $EACH_FILE ...... "
<Your command for that file>
done



That should do.
 
Old 10-24-2007, 02:01 AM   #3
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
While you could probably do it recursively, you would have to be careful. I think it would be easier to let the find command descend the directories for you:

Code:
#!/bin/bash

flag=callmyself

if [ "$1" == $flag ]; then
	shift
        cd "$1"
        echo -n "I am in"
	pwd
        ls
        jhead -autorot -purejpg -exonly *.JPG
else
        find "$1" -type d -exec $0 $flag {} \;
fi
This script calls itself once for each subdirectory find finds. Since the outer level script never changes directory, you don't need to save your original directory. If you want to work your subdirectories from the "bottom up" instead of the "top down" you can add the -depth option to the find command.

I think you could also do what you are trying to do with the single command:

Code:
#!/bin/bash

find "$1" -name "*.JPG" -exec jhead -autorot -purejpg -exonly {} \;
(The space before the "\;" at the end of the find command is necessary.)
 
Old 10-24-2007, 10:51 AM   #4
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Original Poster
Rep: Reputation: 31
Thanks guys. I will try this when I am at home. I think the find solution is the best. I dont need to do anything fancy. I just want it to work and to be clean.
 
Old 10-25-2007, 12:31 AM   #5
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Original Poster
Rep: Reputation: 31
Nice! It works perfectly! I will never had to rotate all those millions of pictures manually again!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
recursively remove directories iAlta Linux - Software 7 10-06-2007 09:25 AM
Remove directories recursively with same name cboyd Linux - Newbie 5 01-14-2007 09:48 PM
Remove files w/ extension txt recursively spiri Linux - General 4 12-14-2005 03:52 AM
Exif info edito for digital photo. chii-chan Linux - Software 0 07-27-2004 04:32 AM
need answer on ipct and exif info in jpg files jensm Linux - Software 1 02-08-2004 12:10 PM


All times are GMT -5. The time now is 04:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration