Re: Re: Checking if directory is empty in postrm

2006-03-09 Thread Gayan Denzil
Dear Sir, I want to testwhether the Folder/Directory is empty by usingjava Can you please send me the source code which is commented out to me as soon as you can. Thank You Gayan Denzil Jayasinghe

Re: Checking if directory is empty in postrm

1998-11-21 Thread Marcus Brinkmann
On Thu, Nov 19, 1998 at 01:47:33AM +, Julian Gilbey wrote: However, a new question arises. Will this work in all cases: rmdir $LDIR 2/dev/null grep -v $LDIR $LDSOCONF $tmpfile mv $tmpfile $LDSOCONF || true rm $tempfile # just in case the mv failed, or grep failed partly Or

Re: Checking if directory is empty in postrm

1998-11-19 Thread Julian Gilbey
However, a new question arises. Will this work in all cases: rmdir $LDIR 2/dev/null grep -v $LDIR $LDSOCONF $tmpfile mv $tmpfile $LDSOCONF || true rm $tempfile # just in case the mv failed, or grep failed partly Or is there any trap door I miss? What if you have a directory

Re: Checking if directory is empty in postrm

1998-11-18 Thread Raul Miller
Cylord [EMAIL PROTECTED] wrote: if [ $(echo * ? .*) = * ? . .. ] ; then echo REALLY empty dir; fi You also need .? or else you're subject to: mkdir emptydir2; touch .* -- Raul

Re: Checking if directory is empty in postrm

1998-11-18 Thread Raul Miller
On Mon, Nov 16, 1998 at 12:28:17AM -0600, [EMAIL PROTECTED] wrote: [ `ls -1A $dir` ] This returns '1' if the directory is empty and '0' otherwise. It is not tricked by spaces or other unusual characters in file names. It's not perfect, however: mkdir emptydir3; cd emptydir3; touch ./-z

Re: Checking if directory is empty in postrm

1998-11-18 Thread Cylord
On Tue, Nov 17, 1998 at 11:04:28PM -0500, Raul Miller wrote: Cylord [EMAIL PROTECTED] wrote: if [ $(echo * ? .*) = * ? . .. ] ; then echo REALLY empty dir; fi You also need .? or else you're subject to: mkdir emptydir2; touch .* With that echo command, 'touch .*' gives an echo result

Re: Checking if directory is empty in postrm

1998-11-18 Thread Chris Waters
Cylord wrote: On Tue, Nov 17, 1998 at 03:05:08PM +0100, Richard Braakman wrote: Chris Waters wrote: if [ $(echo * .*) = * . .. ] ; then echo empty dir; fi [but] touch * [fixed by] if [ $(echo * ? .*) = * ? . .. ] ; then echo REALLY empty dir; fi Good save! And a great demonstration of

Re: Checking if directory is empty in postrm

1998-11-18 Thread Marcus Brinkmann
On Tue, Nov 17, 1998 at 10:15:43AM +0100, Richard Braakman wrote: Marcus Brinkmann wrote: can someone give me a hint how I can efficient test if a certain directory is empty in the postrm (shell script)? If you only want to know if it's empty because you want to remove it, then there's a

Re: Checking if directory is empty in postrm

1998-11-17 Thread Marcus Brinkmann
On Mon, Nov 16, 1998 at 12:28:17AM -0600, [EMAIL PROTECTED] wrote: Marcus Brinkmann writes: [ `ls -1 $dir` ] This does not work. If the dir contains no file, it is [ ], which returns 0, which is fine. If it contains more than one file, it is too many arguments, therefore returning 1,

Re: Checking if directory is empty in postrm

1998-11-17 Thread Richard Braakman
Marcus Brinkmann wrote: can someone give me a hint how I can efficient test if a certain directory is empty in the postrm (shell script)? If you only want to know if it's empty because you want to remove it, then there's a very simple solution: rmdir directory 2/dev/null || true The rmdir

Re: Checking if directory is empty in postrm

1998-11-17 Thread Ben Gertzfield
Marcus == Marcus Brinkmann [EMAIL PROTECTED] writes: Marcus can someone give me a hint how I can efficient test if a Marcus certain directory is empty in the postrm (shell script)? Here's what I did in the /etc/rc.boot/nethack script: # Are there any lock-files to recover? ls

Re: Checking if directory is empty in postrm

1998-11-17 Thread Matthias Klose
Richard Braakman writes: Marcus Brinkmann wrote: can someone give me a hint how I can efficient test if a certain directory is empty in the postrm (shell script)? If you only want to know if it's empty because you want to remove it, then there's a very simple solution: rmdir

Re: Checking if directory is empty in postrm

1998-11-17 Thread Chris Waters
Sorry to provide such a late reply, I was off-list for a couple of days. However, I've reviewed the answers provided so far, and I like mine better. :-) First, the easiest and most obvious way to check if a directory is empty is to rm it. If that succeeds, the directory was empty. Of course,

Re: Checking if directory is empty in postrm

1998-11-17 Thread Richard Braakman
Chris Waters wrote: if [ $(echo * .*) = * . .. ] ; then echo empty dir; fi Brilliant. :-) It has only one flaw. *cough* % mkdir emptydir; cd emptydir % touch * % if [ $(echo * .*) = * . .. ] ; then echo empty dir; fi empty dir *evil grin* Richard

Re: Checking if directory is empty in postrm

1998-11-17 Thread Cylord
On Tue, Nov 17, 1998 at 03:05:08PM +0100, Richard Braakman wrote: Chris Waters wrote: if [ $(echo * .*) = * . .. ] ; then echo empty dir; fi Brilliant. :-) It has only one flaw. *cough* % mkdir emptydir; cd emptydir % touch * % if [ $(echo * .*) = * . .. ] ; then echo empty dir; fi

Re: Checking if directory is empty in postrm

1998-11-16 Thread john
Marcus Brinkmann writes: I need something that returns an error code if the directory is empty but does return 0 if it is non-empty. [ `ls -1 $dir` ] -- John Hasler [EMAIL PROTECTED] (John Hasler) Dancing Horse Hill Elmwood, WI

Re: Checking if directory is empty in postrm

1998-11-16 Thread Raul Miller
Antti-Juhani Kaijanaho [EMAIL PROTECTED] wrote: ls -1 | grep .\* Actually, I'd recommend: ls -A | grep -q . Reasons: (1) You don't care if the display is single or multi-column Thus, the -1 option of ls is useless (2) hidden files would still mean the directory is not empty

Re: Checking if directory is empty in postrm

1998-11-16 Thread john
Marcus Brinkmann writes: [ `ls -1 $dir` ] This does not work. If the dir contains no file, it is [ ], which returns 0, which is fine. If it contains more than one file, it is too many arguments, therefore returning 1, which is also fine. But if it contains one file, it returns 0, which is

Checking if directory is empty in postrm

1998-11-15 Thread Marcus Brinkmann
Hi, can someone give me a hint how I can efficient test if a certain directory is empty in the postrm (shell script)? Thank you, Marcus -- Rhubarb is no Egyptian god.Debian GNU/Linuxfinger brinkmd@ Marcus Brinkmann http://www.debian.orgmaster.debian.org

Re: Checking if directory is empty in postrm

1998-11-15 Thread phumpherys
ls -1 (one) -- Phil Humpherys [EMAIL PROTECTED] DriverSoft Unix Systems Administrator Mobile: +1.801.725.3257 WWW/PGPkeys: http://www.spire.com/~humphery Marcus Brinkmann [EMAIL PROTECTED] writes: Hi, can someone give me a hint how I can efficient test if a certain

Re: Checking if directory is empty in postrm

1998-11-15 Thread Marcus Brinkmann
On Sun, Nov 15, 1998 at 11:23:09AM -0700, [EMAIL PROTECTED] wrote: ls -1 May be I am missing something, but this does only affect the formatting of the output of ls. I need something that returns an error code if the directory is empty but does return 0 if it is non-empty. Marcus Brinkmann

Re: Checking if directory is empty in postrm

1998-11-15 Thread phumpherys
Marcus Brinkmann [EMAIL PROTECTED] writes: On Sun, Nov 15, 1998 at 11:23:09AM -0700, [EMAIL PROTECTED] wrote: ls -1 May be I am missing something, but this does only affect the formatting of the output of ls. -1 won't report . or .., but will return *nothing* of the directory is empty.

Re: Checking if directory is empty in postrm

1998-11-15 Thread Ole J. Tetlie
*-Marcus Brinkmann [EMAIL PROTECTED] | | I need something that returns an error code if the directory is empty but | does return 0 if it is non-empty. I don't know how portable this is, but this seems to work for me in bash: test -d empty -a $(ls -l empty | wc -l) -eq 1 This returns 0 if empty

Re: Checking if directory is empty in postrm

1998-11-15 Thread tmancill
On Sun, 15 Nov 1998, Marcus Brinkmann wrote: I need something that returns an error code if the directory is empty but does return 0 if it is non-empty. $ dirname=whatever_you_want_to_check $ count=$(ls -A1 $dirname 2/dev/null | wc -l) $ echo $count I love shell... BTW, you need the

Re: Checking if directory is empty in postrm

1998-11-15 Thread Antti-Juhani Kaijanaho
On Sun, Nov 15, 1998 at 12:07:39PM -0700, [EMAIL PROTECTED] wrote: I don't know what you'd use with shell if you needed an error code. ls -1 | grep .\* Antti-Juhani -- Antti-Juhani Kaijanaho A7 [EMAIL PROTECTED] ** URL:http://www.iki.fi/gaia/ ** The FAQ is