check whether the directory is empty or not

I have the list of users in user.log, under each user folder there is sub1 folder is there. i want to check whether sub1 is empty or not, if it is empty i have to skip that user user folder and iterate next user folders. i have the sample code,its not giving not proper results.

while read line
do
if [ -d /tmp/$line/sub1 ]
then

if [ find /tmp/$line/sub1 -empty -type d ]
then
echo " empty "
else
echo " not empty"
fi < user.log

can anyone suggest me.

Thanx

if you have Python

#!/usr/bin/env python
import os
users=open("user.log").read().split("\n")
for r,d,f in os.walk("/tmp"):
    if r.split("/")[1] in users:
        if d==[] and f==[]:
            try:
                os.removedirs(r)
            except Exception,e:
                print e
            else:
                print "Directory %s successfully removed." % r
   

Sorry yar..i don't have

i want shell script in unix only..

one google :

http://www.cyberciti.biz/faq/linux-unix-shell-check-if-directory-empty/

I was googling the same, but it did not resolve my problem..sorry..

try the following

this will not read file contents

I apologize. Thats my mistake.

@KiranKumarKarre: you can use the same "while read line" or "cat" the file inside the for loop.

while read line
do
if [ "$(ls -A $line)" ]; then
echo "$line directory hav the file"
else
continue;
fi
done < user.log;

change the path a bit according to your requirement.