Solved

retrieve directory name from a $file variable

Posted on 2008-06-24
4
286 Views
Last Modified: 2013-12-26
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

0
Comment
Question by:terencepires
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21854483
directory=`dirname $file`
0
 
LVL 1

Author Comment

by:terencepires
ID: 21854563
ok but it gives this :

./__Freddy_Lynxx
./__Flamin_Groovies
./__Eddie_and_Ze_Hot_Rods

I need to remove the ./ how can i do ?
0
 
LVL 1

Author Comment

by:terencepires
ID: 21854880
ok I did it like this : file=`echo $file | cut -c3-70`

thanks anyway

Terence
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 21860488
Two better solutions are to do

find *

instead of

find .

or

file=`echo $file | sed "s/^..//"`

instead of

file=`echo $file | cut -c3-70`

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question