Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Finding empty directories

    Hello all :)

    I want to test if a directory is empty or not and I've thought
that I could test for the expansion of dirname/*(DN[1]). If this is an
empty string, then the directory is empty, otherwise it has at least
one file.

    Anyway I was wondering if is there a better way of doing that
using just zsh code, with no external commands (I know I can do a
'find -type d -empty', for example, or 'ls | wc -l', etc...).

    I would like to test if a filename correspond to a dangling
symlink, too. I can find dangling symlinks using **/*(-@), but if I
just have a file listing, how can I test if a file is a dangling
symlink or not? I've found that doing the following test:

    [[ -h file && ( -r file || -d file ) ]]

    will only return true for a symlink that really points to a file
or a directory, and false otherwise, but I'm not sure if this is a
proper way or if it will fail miserably on some obscure case :? In
fact, I'm not sure if '-r' and '-d' follow symlinks by default :?

    Thanks in advance for your help ;)

    Raúl Núñez de Arenas Coronado

Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/

Messages sorted by: Reverse Date, Date, Thread, Author