Link to home
Start Free TrialLog in
Avatar of terencepires
terencepires

asked on

retrieve directory name from a $file variable

Hi

I started this script, in which I would like to get the directory name where $file is located, and put it in a variable. I only want the name of the directory, not the path...

Can someone help ?

Cheers

Terence
#!/bin/sh
thumbdir=/Users/terencepires/Documents/Skydog/Images/for_web/thumb
 
for file in $(find . -type f -iname "*.jpg" -o -iname "*.tif" -o -iname "*.tiff" -o -name "*.gif"); do 
 
#imageMagick format and size conversion 
convert $file -quality 10 -resize 25% $thumbdir$file
done

Open in new window

Avatar of ozo
ozo
Flag of United States of America image

directory=`dirname $file`
Avatar of terencepires
terencepires

ASKER

ok but it gives this :

./__Freddy_Lynxx
./__Flamin_Groovies
./__Eddie_and_Ze_Hot_Rods

I need to remove the ./ how can i do ?
ok I did it like this : file=`echo $file | cut -c3-70`

thanks anyway

Terence
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial