Snippet. Vala. Getting the Size of a File

This snippet shows how to calculate the size of a file in Vala.

File file = File.new_for_path("Hello_World.txt");
try {
    int64 file_size = file.query_info ("*", FileQueryInfoFlags.NONE).get_size ();
    stdout.printf ("File size: %lld bytes\n", file_size);
} catch (Error e) {
    stdout.printf("Error occurred");
}

Updated on: 16 Apr 2024