Check available disk space

Does anyone know how I can write a Ruby script that can check for
available disk space on the current working directory? I’d like to be
able to run the script from Windows and Linux.

When dealing with file systems, I usually find myself switching on a
File.exists?

result = (File.exists?(‘C:\’) ? dir /-C : df .).split("\n").last
=> “/dev/sda1 110650276 52580520 52449016 51% /”

This assumes only two filesystem styles (Windows and Linux)

On Sep 16, 10:17 am, jim [email protected] wrote:

Does anyone know how I can write a Ruby script that can check for
available disk space on the current working directory? I’d like to be
able to run the script from Windows and Linux.

gem install sys-filesystem

Regards,

Dan

Hi. I have created gem specifically for checking free disk space:

Woot, i didn’t know about ‘dir /-C’

Shame on my windows-noob head. Ruby is even nice on windows! :slight_smile:

Here is a guide for check disk space in linux.

https://www.puttygen.com/du-command