Re: Empty Directory problem
From: John (jguad98_at_hotmail.com)
Date: 10/28/03
- Next message: Walt R: "Re: communicate with more than processes/threads?"
- Previous message: William Park: "Re: deleting file with special character in name"
- In reply to: newexpectuser: "Empty Directory problem"
- Next in thread: Stephane CHAZELAS: "Re: Empty Directory problem"
- Reply: Stephane CHAZELAS: "Re: Empty Directory problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Oct 2003 16:17:17 -0800
anthonypieper@cs.com (newexpectuser) wrote:
> ... I just want to do the following:
>
>
> if [ $DIR is empty ]
> echo "The directory is empty" > $LOG/logfile.dat
> exit
> fi
>
what shell? what OS? in ksh on most unix's, if you do "ls /mydir"
and "/mydir" is empty you get a null return ... if you do "ls -l
/mydir" and it is empty, you get the message "total 0" which indicates
an empty dir ... so your test could look like this:
if [ -d $DIR ] # test to see if $DIR exists
then
if [ `ls -l $DIR` == "total 0" ]
then echo "the directory is empty" >/yourlogfile
else echo "the dir is not empty"
fi
else echo "$DIR does not exist"
fi
Don't forget to read the manpage for ls to find the relevant forms for
your shell & OS.
regards,
John
- Next message: Walt R: "Re: communicate with more than processes/threads?"
- Previous message: William Park: "Re: deleting file with special character in name"
- In reply to: newexpectuser: "Empty Directory problem"
- Next in thread: Stephane CHAZELAS: "Re: Empty Directory problem"
- Reply: Stephane CHAZELAS: "Re: Empty Directory problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|