Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: "Adam Price" <adam@pappnase.demon.co.uk>
Subject: Re: Check for files in a directory
Date: Thu, 26 Oct 2000 07:28:21 +0100	[thread overview]
Message-ID: <972542253.12957.1.nnrp-03.c2deb51d@news.demon.co.uk> (raw)
In-Reply-To: svernidqsb8975@corp.supernews.com


"Arthur Dalessandro" <adalessandro@odione.com> wrote in message news:svernidqsb8975@corp.supernews.com...
> I've seen the man test pages, which show if a file exists, is there a quick
> and dirty way of checking whether a given directory contains any files?  I
> have a cron job that I want to run, the job should only be run if these temp
> files exist in the given directory.  Any help would be appreciated.
>
>
You can do something like

cd $dir
count=$(ls -la | wc -l)

and check for a count greater than 2, or you can make use of the fact that
rmdir will fail if there are files in the directory. If it succeeds then recreate the
dir.

Hope this helps
Adam
PS Try searching comp.unix.shell on deja.com this question has come up recently
and I think there were some better answers than the 2 I gave above but I'm not
sure.




  parent reply	other threads:[~2000-10-26  6:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-25  4:00 Check for files in a directory Arthur Dalessandro
2000-10-26  6:17 ` Eckhardt Wallmeroth
2000-10-26  6:28 ` Adam Price [this message]
2000-10-26  9:07 ` Joerg Bruehe
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox