You can cut the *
from the directory name instead of completely ignoring it:
[[ $file == *"*" ]] && file="${file/%\*/}"
#this goes inside the second loop
Or if you want to ignore the empty directory:
[[ -d $dir && $ls -A $dir) ]] || continue
#this goes inside the first loop
Another way:
files=$(shopt -s nullglob dotglob; echo "$dir"/*)
(( ${#files} )) || continue
#this goes inside the first loop
Or you can turn on the nullglob
(mentioned by Etan Reisner) and dotglob
altogether:
shopt -s nullglob dotglob
#This goes before first loop.
From Bash Manual
nullglob
If set, Bash allows filename patterns which match no files to expand
to a null string, rather than themselves.
dotglob
If set, Bash includes filenames beginning with a ‘.’ in the results of
filename expansion.
Note: dotglob
includes hidden files (files with a .
at the beginning in their names)