Deleting directories
I am searching for a method of deleting directories in Lisp. I am currently
only interested in getting it to work under Windows. I was surprised to
discover that there appears to be no direct way to remove a directory, even
though there is a way to create one. I attempted to remove the directory
using:
(delete-file "d:\\code\\lisp\\bleh\\")
and receved this error:
Error: Failed to DELETE file d:\code\lisp\bleh\: 5: Access is denied.(5).
I also tried using an inteface to the windows API as follows:
(fli:define-foreign-function
(remove-directory "RemoveDirectoryA")
((lpstring :pointer))
:result-type long)
(fli:define-foreign-function
(last-win32-err "GetLastError")
()
:result-type long)
(defun rmdir(path)
(let ((external-format (if (string= (software-type) "Windows NT")
:unicode
:ascii))
(error-code nil))
(fli:with-foreign-string (new-ptr element-count byte-count
:external-format external-format)
path
(declare (ignore element-count byte-count))
(setq error-code (remove-directory new-ptr))
(unless (not (zerop error-code))
(setq error-code (last-win32-err))
(format t "Error Code: ~A~%" error-code)))))
Which does not work and windows returns an error 2, which I believe is a
file not found error.
Any suggestions? Does anyone out there have a similar issue? Is my code
broken in some way I am missing? Any assistance would be greatly
appreciated.
Paul D. Lathrop