Is there a way to find out free disk space equivalent to psutil.disk_usage('/') in python

question

#1

Is there a way to find out free disk space in drive C: both on windows and linux ?
On python I would that by calling
psutil.disk_usage(‘C:’).free


#2

It seems not…

If you are OK with using python from Julia you could probably use:

julia> using PyCall

julia> @pyimport shutil

julia> shutil.disk_usage("/")

If you like to play with lower level (see doc) you could write something similar to:

julia> function disk_free_space(path)
          if Sys.islinux()  # maybe isunix would work here too?
            statfs = zeros(UInt64, 11)  # warning: I am not sure all platform use unsigned long for all fields. See `man statvfs`
            ccall((:statvfs, "libm.so.6"), Cint, (Cstring,Ptr{Cvoid}), "/", statfs)
            convert(Int, statfs[1]*statfs[5])
          elseif Sys.iswindows()
             # you could call GetDiskFreeSpaceExA from kernel32.dll 
             # something like ->
             # ccall( (:GetDiskFreeSpaceExA, "kernel32.dll"), stdcall, ... )  
             # sry I have no windows to try
          else throw(ErrorException("Unsupported platform"))
          end
       end

#3

Thanks I like the low level solution…