This is what I came up with
#!/bin/bash
dnames=$(for i in $(ls -d $1*/); do echo ${i}; done)
if [ "$#" -eq "1" ]; then
for dir in $dnames
do
cd $1
cd $dir
if [ -d "drawings" ]; then
cd drawings
jpgfiles=$(ls -p | grep -v / | awk '/.jp[e]?g/{print $0}')
if [ -z "$jpgfiles" ]; then
echo "Directory drawings exist in $dir but no .jpg images were found"
else
for jpgs in $jpgfiles
do
echo "found $jpgs in ${dir}drawings" #convert $jpgs -crop 713x470+5+3 output.jpg
done
fi
else
echo "Directory drawings cannot be found in $dir"
fi
done
else
echo "A full path to the directory must be given"
echo "For instance, /home/user1/Pictures/"
fi
This should be run with one parameter, in which the parameter is the full path to the directory. For example, if I'm going to look for that drawings folder that may be located in a subdirectory in my /home/joram/ directory
It would be like this
myprogram /home/joram/
The program loops in /home/joram/ through all the directories it contains. Then it visits every directory in /home/joram/ in hopes of finding drawings subfolder. When the program finds drawings folder that contains .jpg images, the commands are triggered. After finishing the commands, the program continues loop as long as all the directories are checked.
Example of an output of the program:
#Directory drawings cannot be found in /home/joram/Desktop/
#Directory drawings cannot be found in /home/joram/Documents/
#Directory drawings exist in /home/joram/Downloads/ but no .jpg images were found
#Directory drawings cannot be found in /home/joram/Music/
#Directory drawings cannot be found in /home/joram/my_scripts/
#found test2.jpeg in /home/joram/Pictures/drawings
#found test.jpg in /home/joram/Pictures/drawings
#Directory drawings cannot be found in /home/joram/Public/
NOTE: In it's current form, the program just prints the .jpg files it found and gives some other information as well (No other commands triggered). This way it can be tested before doing an actual thing. To make the program get what you want, delete the echo part and uncomment the command on line 16 (If that is the actual command you want to run).
Improvements could be made, hope this helps you anyway!