Too many arguments?

I can't find anything wrong with this line of code, it works when there is one file in the directory but more than one i get a "too many arguements2 error

if [ -z $(ls $dname) ]; then

am i missing something?

The command "$(ls $dname)" returns you the list of files in the directory ...
So, if you have more one file in it, your result is "if [ -z file1 file2 file3 ... ]" !!!

Try this :

if [ $(ls $dname | wc -l) -eq 0 ] ; then

Good luck

Works a treat ...Thank you!

Another way to do it without the pipe into wc:

if [ ! "$(ls -A $dirname)" ];then echo "empty dir";fi