title: reading sub-directories with bash
body: <p>I have a folder that contains couple hundred folders with images, inside each of thous folders are 4 images with random names, what I need to do is loop through all the subfolders, read the 4 image names of each sub-folder and run this command on them:</p>
  
  <pre><code> convert \( $subdir/$file1.jpg $subdir/$file2.jpg -append \) \( $subdir/$file3.jpg $subdir/$file4.jpg -append \) +append $subdir.jpg
  </code></pre>
  
  <p>This is how it should work:</p>
  
  <pre><code>foreach(subdirectory in directory){
     $img_arr[] = new Array(); 
     foreach(file in subdirectory){
         $img_arr[] = file;
     }
  
     exec("convert \( $subdirectory /$img_arr[0].jpg $subdirectory /$img_arr[1].jpg -append \) \( $subdirectory/$img_arr[2].jpg $subdirectory/$img_arr[3].jpg -append \) +append $subdirectory.jpg");
  }
  </code></pre>
  
  <p>This is what I got so far:</p>
  
  <pre><code>#!/bin/bash
  
  img=0;
  
  IFS=$'\n'
  
  for NAME in $(find -type f)
    do
     echo "Found a file: \"$NAME\""
  done
  </code></pre>
  
  <p>I'm trying to combine 4 images into one using imagemagick. Thanks!</p>