muyinliu
muyinliu

Reputation: 91

how to get Disk Space used/free/total in Common Lisp

Seems that there is no standard functions to get used/free/total of Disk space in Common Lisp.

There is statvfs.h in Linux/Mac and GetDiskFreeSpaceEx function in Windows for C/C++.

Upvotes: 1

Views: 357

Answers (2)

muyinliu
muyinliu

Reputation: 91

I wrote a new project cl-diskspace using statvfs to get disk total/free/available space in Common Lisp. Support Mac/Linux/Windows.

Update: 2015-07-11 now support Windows! Thanks to pjb, Guthur, Fare, |3b|

Install cl-diskspace with QuickLisp:

$ git clone https://github.com/muyinliu/cl-diskspace.git
$ cp -r cl-diskspace ~/quicklisp/local-projects/

Load cl-diskspace with QuickLisp:

(ql:quickload 'cl-diskspace)

Usage of cl-diskspace:

Get disk space information

(diskspace:disk-space "/")

Will get something like this:

127175917568
16509661184
16247517184

Means that the total space is 118.44G, free space is 15.38G and available space is 15.13G

Get disk total space

(diskspace:disk-total-space "/")

Will get something like this:

127175917568

Get disk free space

(diskspace:disk-free-space "/")

Will get something like this:

16509661184

Get disk available space

(diskspace:disk-available-space "/")

Will get something like this:

16247517184

Upvotes: 0

fstamour
fstamour

Reputation: 789

Personally, it would call an executable to do that using a library. Calling df -h with IOLib for example. But this is not portable (particularly IOLib, but there are other libraries), and you have to parse the output of the commands.

That's one reason I love programs which have "machine readable" outputs: you can glue them up programmatically (à la shell script).

Another way would be to actually call these c function, using cffi or uffi (ffi standing for foreign function interface), but I haven't used neither, so I can't say much about it.

Oh, search on quickdocs.org, there is probably a library exactly for that, or maybe just to access the OS's API.

Upvotes: 2

Related Questions