Reputation: 91
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
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|
$ git clone https://github.com/muyinliu/cl-diskspace.git
$ cp -r cl-diskspace ~/quicklisp/local-projects/
(ql:quickload 'cl-diskspace)
(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
(diskspace:disk-total-space "/")
Will get something like this:
127175917568
(diskspace:disk-free-space "/")
Will get something like this:
16509661184
(diskspace:disk-available-space "/")
Will get something like this:
16247517184
Upvotes: 0
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