* quick and dirty test for empty directory
@ 2022-11-16 16:17 Ray Andrews
2022-11-16 16:23 ` Roman Perepelitsa
0 siblings, 1 reply; 3+ messages in thread
From: Ray Andrews @ 2022-11-16 16:17 UTC (permalink / raw)
To: Zsh Users
Best advice googling for such a test is this:
[ -d "$dir" ] && [ -n "$(ls -A $dir)" ] # If true,
dir isn't empty.
... but experimenting:
2 /media/sdb 0 $ [ /media/sdb/3/* ] && echo file found
2 /media/sdb 0 $ [ /media/sdb/2/* ] && echo file found
file found
... correct result. I does have a certain logic to it. If there's no
expansion then the test fails. Dare I use it or is this bound to crash
and burn somehow or other? Anyway I can't believe a call to 'ls' is
really needed.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: quick and dirty test for empty directory
2022-11-16 16:17 quick and dirty test for empty directory Ray Andrews
@ 2022-11-16 16:23 ` Roman Perepelitsa
2022-11-16 18:00 ` Ray Andrews
0 siblings, 1 reply; 3+ messages in thread
From: Roman Perepelitsa @ 2022-11-16 16:23 UTC (permalink / raw)
To: Ray Andrews; +Cc: Zsh Users
On Wed, Nov 16, 2022 at 5:18 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Best advice googling for such a test is this:
>
> [ -d "$dir" ] && [ -n "$(ls -A $dir)" ] # If true,
> dir isn't empty.
Try this:
[[ -n $dir(#qNF) ]] && print -r -- "$dir is a non-empty directory"
This requires extended_glob.
Roman.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: quick and dirty test for empty directory
2022-11-16 16:23 ` Roman Perepelitsa
@ 2022-11-16 18:00 ` Ray Andrews
0 siblings, 0 replies; 3+ messages in thread
From: Ray Andrews @ 2022-11-16 18:00 UTC (permalink / raw)
To: zsh-users
On 2022-11-16 08:23, Roman Perepelitsa wrote:
> [[ -n $dir(#qNF) ]] && print -r -- "$dir is a non-empty directory"
Looks good. And seems to obviate the '-d' test as well.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-16 18:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 16:17 quick and dirty test for empty directory Ray Andrews
2022-11-16 16:23 ` Roman Perepelitsa
2022-11-16 18:00 ` Ray Andrews
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).