marc
marc

Reputation: 2187

How can I locate a specific file in a directory within a loop?

I'm having trouble pointing to a specific file containing part of the string of another file in another directory.

If you look at the following command, lets say I have a file abc.foo in ./A, I need to apply a function by using abc_extendedname1.jpeg which is in ./B

for file in ./A/*; 

do echo $file;
function $file -opt ./B/${file%.foo}_extendedname1.jpeg ./B/${file%.foo}_extendedname2.jpeg;

done

Any help would be greatly appreciated!

Upvotes: 0

Views: 134

Answers (2)

Axel Amthor
Axel Amthor

Reputation: 11096

try

export d="`pwd`"
find ./A/*|while read file
do
    echo "$file"
    if [ -f  "$d/B/${file}_extendedname1.jpeg" ]
    then
        echo "$d/B/${file}_extendedname1.jpeg" found
    fi
done

Upvotes: -1

Charles Duffy
Charles Duffy

Reputation: 295530

for file in ./A/*; do
  basename=${file##*/}
  basename_noext=${basename%.*}
  echo "$file"
  your_function "$file" -out \
    "./B/${basename_noext}_extendedname1.jpeg" \
    "./B/${basename_noext}_extendedname2.jpeg"
done

Upvotes: 2

Related Questions