Snippet. Vala. Creating File Objects

The GIO package in Vala works transparently across different protocols. There is no difference if it is done directly on the file system, or through a protocol like - HTTP, FTP, SFTP, SMB or DAV. This is implemented by a virtual file system layer called GVFS which is designed to be extendable for backends of other protocols.

var data_file = File.new_for_path ("data.txt");
var message_of_the_day = File.new_for_path ("/etc/motd");
var home_dir = File.new_for_path (Environment.get_home_dir ());
var web_page = File.new_for_uri ("http://live.gnome.org/Vala");

These methods are static factory methods and create instances of classes implementing File.


Updated on: 03 Dec 2024