ruricolist / trivial-file-size

Stat a file's size in Common Lisp.
MIT License
16 stars 5 forks source link

Lispworks Windows support #6

Closed apr3vau closed 6 months ago

apr3vau commented 6 months ago

We seem have a universal way to get file size efficiently in Lispworks, using the fast-directory-files facility.fast-directory-files)

The following code works for me under Lispworks 8 Windows:

(defun file-size (file)
  (fast-directory-files
   file
   #'(lambda (f handle)
       (declare (ignore f))
       (return-from file-size (fdf-handle-size handle)))))

According to the release note 12.15.6 of Lispworks 8.0, such method seems can only be used in version above 8.0. But even under 8.0 such a function may also work (by iterating directory to find the target):

(defun file-size (file)
  (fast-directory-files
   file
   #'(lambda (f handle)
       (when (string= f (file-namestring file))
         (return-from file-size (fdf-handle-size handle))))))

Maybe we can use such a method to get file size on other platforms in Lispworks?

ruricolist commented 6 months ago

That sounds like a good idea. If you'd like to make a pull request, I'd be happy to merge it.

There's a reference in https://www.lispworks.com/documentation/lw80/lw/lw-common-lisp-18.htm#common-lisp_marker-line-1630 on how to conditionalize code for different LispWorks versions, so we could use the version >8 technique when available.

apr3vau commented 6 months ago

Thank you! I tried myself and it seems work on my machine, hoping for your review! #7