[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to test for empty dir?
From: |
Marc Herbert |
Subject: |
Re: best way to test for empty dir? |
Date: |
Fri, 11 Dec 2009 10:43:12 +0000 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090320) |
>>> empty_dir()
>>> {
>>> test "x$(echo $1/*$2)" = "x$1"'/*'"$2"
>>> }
pk wrote:
> This fails if the directory contains a file called "*".
Yes. Unlike the ones below, empty_dir() above considers as empty a
directory that has a SINGLE element named '*'. Since I am not so
interested in files named '*', I think I can live with that!
Chris & others wrote:
>> is_file2()
>> {
>> for f
>> do
>> [ -e "$f" ] && return
>> done
>> return 1
>> }
I think I like this one.
Andreas:
> This will still fail if the first file happens to be a dangling symlink.
Yes, but I think it's valuable to refine "fail" again. Dangling symlinkS
(not just the first one) will be ignored, just like they were not
here. Some might find this acceptable.
For purists, does this one works even better?
is_file3()
{
for f
do
[ -e "$f" -o -L "$f" ] && return
done
return 1
}
Thanks to everyone who answered, appreciated.
- best way to test for empty dir?, Marc Herbert, 2009/12/10
- Re: best way to test for empty dir?, Greg Wooledge, 2009/12/10
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/10
- Re: best way to test for empty dir?, Chris F.A. Johnson, 2009/12/10
- Message not available
- Re: best way to test for empty dir?, pk, 2009/12/10
- Re: best way to test for empty dir?, pk, 2009/12/10
- Re: best way to test for empty dir?,
Marc Herbert <=
- Message not available
- Re: best way to test for empty dir?, pk, 2009/12/11
- Re: best way to test for empty dir?, Sven Mascheck, 2009/12/11
- Re: best way to test for empty dir?, Chris F.A. Johnson, 2009/12/11
- Re: best way to test for empty dir?, Sven Mascheck, 2009/12/11
- Re: best way to test for empty dir?, Marc Herbert, 2009/12/11
- Re: best way to test for empty dir?, Greg Wooledge, 2009/12/11
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/11
- Re: best way to test for empty dir?, Andreas Schwab, 2009/12/12
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/12
- Re: best way to test for empty dir?, Marc Herbert, 2009/12/14