Snippet. Vala. Find If File Exists with FileUtils

This snippet shows how to find, if a file exists in Vala.

The FileUtils class from the GLib package is very convenient, when working with text files. However, if the file we want to work with does not exist, an error may be thrown. In such case, the method test in the class FileUtils comes handy, to find if a file already exists.

if (FileUtils.test("data.txt",GLib.FileTest.EXISTS) == false) {
    // File does not exist.
} else {
    // File exist.
}

Updated on: 28 Mar 2024