Next Prev Up Top Contents Index

with-file-stats

Macro
Summary

Returns information on a file.

Package

lispworks

Signature

with-file-stats (&rest stats ) pathname if-form if-not-form => form-result

Arguments

stats

Any of: author, length, write-date.

pathname

A pathname.

if-form

A form that gets executed if the pathname can be accessed.

if-not-form

A form that gets executed if the pathname cannot be accessed.

Values

form-result

The result of executing whichever of if-form and if-not-form is executed.

Description

The with-file-stats macro is a more efficient way of interrogating a file for author, length, and write-date if more than one needs to be known.

Example

Without this function, a simple file interrogation function might look like this:

(defun print-file-info (pathname)
  (if (file-readable-p pathname)
      (format t "~%Author: ~A~%Size: ~A~%Write-Date: ~A~%"
      (file-author pathname)
      (file-length pathname)
      (file-write-date pathname))
    (format t "Cannot read ~A" pathname)))

The function can be written more efficiently using with-file-stats :

(defun print-file-info (pathname)
  (with-file-stats (author length write-date) pathname
   (format t "~%Author: ~A~%Size: ~A~%Write-Date: ~A~%"
author
length
write-date
(format t "Cannot read ~A" pathname))))

LispWorks Reference Manual - 14 Dec 2001

Next Prev Up Top Contents Index