get system free disk space in rust

To get the available free disk space on a system in Rust, we can use the sysinfo crate. This crate provides a cross-platform interface for retrieving system information, including disk space information.

Here's an example code snippet:

main.rs
use sysinfo::{DiskExt, System, SystemExt};

fn main() {
    let system = System::new_all();

    // Retrieves a list of disks on the system
    let disks = system.get_disks();

    for disk in disks {
        // Retrieves the available space on the disk in bytes
        let available_space = disk.get_available_space();

        println!("Disk {} has {} bytes available", disk.get_name(), available_space);
    }
}
416 chars
16 lines

This code will output a list of disks on the system along with their available free space in bytes. Note that this code is cross-platform, meaning it will work on Windows, macOS, and Linux systems.

gistlibby LogSnag