summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisplib.c1
-rw-r--r--share/txr/stdlib/path-test.tl9
-rw-r--r--txr.128
3 files changed, 38 insertions, 0 deletions
diff --git a/lisplib.c b/lisplib.c
index 30b2152a..78d6c024 100644
--- a/lisplib.c
+++ b/lisplib.c
@@ -190,6 +190,7 @@ static val path_test_set_entries(val dlt, val fun)
lit("path-newer"), lit("path-older"),
lit("path-same-object"), lit("path-private-to-me-p"),
lit("path-strictly-private-to-me-p"),
+ lit("path-dir-empty"),
nil
};
diff --git a/share/txr/stdlib/path-test.tl b/share/txr/stdlib/path-test.tl
index ee211ff2..4ebb1e3e 100644
--- a/share/txr/stdlib/path-test.tl
+++ b/share/txr/stdlib/path-test.tl
@@ -174,3 +174,12 @@
(and s0 s1
(eql s0.dev s1.dev)
(eql s0.ino s1.ino)))))
+
+(defun path-dir-empty (path)
+ (when (path-dir-p path)
+ (let ((name (if (stringp path) path path.path)))
+ (with-stream (ds (open-directory name))
+ (for (ent) ((set ent (get-line ds)) t) ()
+ (casequal ent
+ (("." ".."))
+ (t (return nil))))))))
diff --git a/txr.1 b/txr.1
index 6d214246..5ea0cac6 100644
--- a/txr.1
+++ b/txr.1
@@ -58016,6 +58016,34 @@ for a socket and
.code path-pipe-p
for a named pipe.
+.coNP Function @ path-dir-empty
+.synb
+.mets (path-dir-empty << path )
+.syne
+.desc
+The
+.code path-dir-empty
+function returns
+.code t
+if
+.meta path
+is an empty directory.
+
+Implementation note: this function performs a test similar to
+.codn path-dir-p ;
+then, if it is confirmed that
+.meta path
+is a directory, a directory stream is opened and entries are read.
+If an entry is seen which has a name other than
+.str .
+or
+.str ..
+then it is concluded that the directory is not empty and
+.code nil
+is returned. If no such entry is seen, then the directory is deemed empty and
+.code t
+is returned.
+
.coNP Functions @, path-setgid-p @ path-setuid-p and @ path-sticky-p
.synb
.mets (path-setgid-p << path )