source: trunk/j/src/org/armedbear/lisp/ensure-directories-exist.lisp @ 9266

Last change on this file since 9266 was 5412, checked in by piso, 17 years ago

Initial checkin.

File size: 2.1 KB
Line 
1;;; ensure-directories-exist.lisp
2;;;
3;;; Copyright (C) 2004 Peter Graves
4;;; $Id: ensure-directories-exist.lisp,v 1.1 2004-01-07 19:51:14 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20;;; Adapted from SBCL.
21
22(in-package "SYSTEM")
23
24(defun ensure-directories-exist (pathspec &key verbose)
25  (let ((pathname (pathname pathspec))
26  (created-p nil))
27    (when (wild-pathname-p pathname)
28      (error 'file-error
29       :format-control "Bad place for a wild pathname."
30       :pathname pathname))
31    (let ((dir (pathname-directory pathname)))
32      (loop for i from 1 upto (length dir)
33        do (let ((newpath (make-pathname
34                           :host (pathname-host pathname)
35                           :device (pathname-device pathname)
36                           :directory (subseq dir 0 i))))
37             (unless (probe-file newpath)
38               (let ((namestring (namestring newpath)))
39                 (when verbose
40                   (fresh-line)
41                   (format *standard-output*
42                           "Creating directory: ~A~%"
43                           namestring))
44                 (mkdir namestring)
45                 (unless (probe-file namestring)
46                   (error 'file-error
47                          :pathname pathspec
48                          :format-control "Can't create directory ~A."
49                          :format-arguments (list namestring)))
50                 (setf created-p t)))))
51      (values pathname created-p))))
Note: See TracBrowser for help on using the repository browser.