[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Portably know the name of the filesystem root directory
From: |
Florian Kaufmann |
Subject: |
Portably know the name of the filesystem root directory |
Date: |
Wed, 28 Mar 2012 19:25:00 -0000 |
User-agent: |
G2/1.0 |
I am programming an emacs lisp function which searches a file from a
specific point in the directory tree towards the root. But how can I
portably dedect when root is reached? The name of the root is "/" on
unixes, is probably something like "[A-Z]:" (a regex) on DOS, and
probably even something else on an apple OS. This is what I have so
far, but I fear it only works on Unixes.
(defun mks-file-to-sandbox(file)
"Returns the sandbox file (.pj) the given FILE is a member of."
(let* ((dir (file-name-directory file))
sandboxes)
(while (not (setq sandboxes (directory-files dir t ".*\\.pj$" t)))
(when (string= dir "/")
(error "no sandbox found"))
(setq dir (file-name-directory dir)))
(when (< (length sandboxes) 1)
(message "found multiple sandboxes, choosing the first: %S"
sandboxes))
(car sandboxes)))
- Portably know the name of the filesystem root directory,
Florian Kaufmann <=