Re: Empty Directory problem
From: Scott McMillan (smcm_at_usa.net)
Date: 10/27/03
- Next message: jmdevil: "Re: Empty Directory problem"
- Previous message: Dan Mercer: "Re: Empty Directory problem"
- In reply to: newexpectuser: "Empty Directory problem"
- Next in thread: jmdevil: "Re: Empty Directory problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Oct 2003 16:09:41 -0500
On 27 Oct 2003 10:55:02 -0800, anthonypieper@cs.com (newexpectuser)
wrote:
>I have a script running and I want to see if a directory is empty
>(meaning not having any files).
>
>I can't use the rmdir, because I don't want to remove the directory, I
>just want to do the following:
>
>
>if [ $DIR is empty ]
> echo "The directory is empty" > $LOG/logfile.dat
> exit
>fi
>
>Thank you
I wonder if this would work for you (filenames starting with a period
would be found as well, subdirectories not checked):
cd /<yourdirectoryname>
if [ -z `find ./ -type f -print` ]; then
echo "Directory is empty"
else
echo "Directory contains files"
fi
If you are not concerned with whether or not 'hidden' (filenames
beginning with a period) are in the directory, I think you could use
something like:
cd /yourdirectoryname
ls -l | grep "total 0" >/dev/null
if [ $? = 0 ]; then
echo "Directory is empty"
else
echo "Directory contains files"
fi
However, subdirectories within <yourdirectoryname> would trigger
"Directory contains files".
Scott McMillan
- Next message: jmdevil: "Re: Empty Directory problem"
- Previous message: Dan Mercer: "Re: Empty Directory problem"
- In reply to: newexpectuser: "Empty Directory problem"
- Next in thread: jmdevil: "Re: Empty Directory problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|