Search code examples
bashunixloopsfilenames

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!


Solution

  • 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