| 1 |
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL; Base: 10 -*- |
|---|
| 2 |
;;; $Header: /usr/local/cvsrep/cl-fad/corman.lisp,v 1.4 2008/03/12 00:10:43 edi Exp $ |
|---|
| 3 |
|
|---|
| 4 |
;;; Copyright (c) 2004-2008, Dr. Edmund Weitz. All rights reserved. |
|---|
| 5 |
|
|---|
| 6 |
;;; Redistribution and use in source and binary forms, with or without |
|---|
| 7 |
;;; modification, are permitted provided that the following conditions |
|---|
| 8 |
;;; are met: |
|---|
| 9 |
|
|---|
| 10 |
;;; * Redistributions of source code must retain the above copyright |
|---|
| 11 |
;;; notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
|
|---|
| 13 |
;;; * Redistributions in binary form must reproduce the above |
|---|
| 14 |
;;; copyright notice, this list of conditions and the following |
|---|
| 15 |
;;; disclaimer in the documentation and/or other materials |
|---|
| 16 |
;;; provided with the distribution. |
|---|
| 17 |
|
|---|
| 18 |
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHORS 'AS IS' AND ANY EXPRESSED |
|---|
| 19 |
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 20 |
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 21 |
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|---|
| 22 |
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 23 |
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
|---|
| 24 |
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 25 |
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 26 |
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 27 |
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 28 |
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 29 |
|
|---|
| 30 |
(in-package :cl) |
|---|
| 31 |
|
|---|
| 32 |
(defun wild-pathname-p (pathspec &optional field) |
|---|
| 33 |
(unless (pathnamep pathspec) |
|---|
| 34 |
(setq pathspec (pathname pathspec))) |
|---|
| 35 |
(labels ((name-wild-p (name) |
|---|
| 36 |
(or (eq :wild name) |
|---|
| 37 |
(and (stringp name) |
|---|
| 38 |
(string= "*" name)))) |
|---|
| 39 |
(dir-wild-p (dir) |
|---|
| 40 |
(or (find :wild dir) |
|---|
| 41 |
(find :wild-inferiors dir) |
|---|
| 42 |
(find "*" dir :test #'string=)))) |
|---|
| 43 |
(case field |
|---|
| 44 |
((:name) |
|---|
| 45 |
(name-wild-p (pathname-name pathspec))) |
|---|
| 46 |
((:type) |
|---|
| 47 |
(name-wild-p (pathname-type pathspec))) |
|---|
| 48 |
((:directory) |
|---|
| 49 |
(dir-wild-p (pathname-directory pathspec))) |
|---|
| 50 |
((nil) |
|---|
| 51 |
(or (name-wild-p (pathname-name pathspec)) |
|---|
| 52 |
(name-wild-p (pathname-type pathspec)) |
|---|
| 53 |
(dir-wild-p (pathname-directory pathspec)))) |
|---|
| 54 |
(t nil)))) |
|---|
| 55 |
|
|---|
| 56 |
(defun file-namestring (pathspec) |
|---|
| 57 |
(flet ((string-list-for-component (component) |
|---|
| 58 |
(cond ((eq component :wild) |
|---|
| 59 |
(list "*")) |
|---|
| 60 |
(component |
|---|
| 61 |
(list component)) |
|---|
| 62 |
(t nil)))) |
|---|
| 63 |
(let* ((pathname (pathname pathspec)) |
|---|
| 64 |
(name (pathnames::pathname-internal-name pathname)) |
|---|
| 65 |
(type (pathnames::pathname-internal-type pathname))) |
|---|
| 66 |
(format nil "~{~A~}~{.~A~}" |
|---|
| 67 |
(string-list-for-component name) |
|---|
| 68 |
(string-list-for-component type))))) |
|---|
| 69 |
|
|---|
| 70 |
(in-package :win32) |
|---|
| 71 |
|
|---|
| 72 |
(defwinapi RemoveDirectory |
|---|
| 73 |
((lpPathName LPCSTR)) |
|---|
| 74 |
:return-type BOOL |
|---|
| 75 |
:library-name "Kernel32" |
|---|
| 76 |
:entry-name "RemoveDirectoryA" |
|---|
| 77 |
:linkage-type :pascal) |
|---|
| 78 |
|
|---|
| 79 |
(defun delete-directory (pathspec) |
|---|
| 80 |
"Deletes the empty directory denoted by the pathname designator |
|---|
| 81 |
PATHSPEC. Returns true if successful, NIL otherwise." |
|---|
| 82 |
(win:RemoveDirectory |
|---|
| 83 |
(ct:lisp-string-to-c-string |
|---|
| 84 |
(namestring (pathname pathspec))))) |
|---|
| 85 |
|
|---|
| 86 |
(export 'delete-directory) |
|---|