Check for empty directory (Bash)

Uit De Vliegende Brigade
Ga naar: navigatie, zoeken

Bv.:

# Remove images from <site>/dvb/images
###############################
#
test_dir="$site_path""/dvb/images"
test_dir_asterisk="$site_path""/dvb/images/*"

if [ -n "$(ls -A "$test_dir" 2>/dev/null)" ]
then
  echo "   ""$test_dir"" contains files"
  rm $test_dir_asterisk
else
  echo "   ""$test_dir"" does not contain files"
fi

Bronnen