You can exclude * from the directory name and not completely ignore it:
[[ $file == *"*" ]] && file="${file/%\*/}"
Or, if you want to ignore an empty directory:
[[ -d $dir && $ls -A $dir) ]] || continue
Another way:
files=$(shopt -s nullglob dotglob; echo "$dir"/*) (( ${#files} )) || continue
Or you can include nullglob (mentioned by Etan Reisner ) and dotglob in general:
shopt -s nullglob dotglob
From Bash Manualnullglob
If set, Bash resolves file name patterns that do not match files for extension to an empty string, not to itself.
dotglob
If set, Bash contains file names starting with the 'character. in the results is the file name extension.
Note: dotglob contains hidden files (files with . In the beginning in their names)
Jahid source share