An example is attached.
I hope you help!

El 25/12/11 14:15, Edwin DLCA escribió:
> Someone can help me with some examples of FileMonitor, NEED monitor a folder
> if some file is created or deleted, thanks for your help.
> 
> 
> 
> 
> _______________________________________________
> vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
public static int main(string[] args)
{
    var loop = new MainLoop();
    
    if(args.length == 1){
        stderr.printf("Usage: %s <directory>\n", args[0]);
        return 1;
    }
    
    var directory = File.new_for_commandline_arg(args[1]);
    if(!directory.query_exists() || directory.query_file_type(FileQueryInfoFlags.NONE) != FileType.DIRECTORY){
        stderr.printf("'%s' does not exists or it's not a directory\n", directory.get_path());
        return 1;
    }
    
    try{
        var monitor = directory.monitor(FileMonitorFlags.NONE);
        monitor.changed.connect((file, other_file, event_type) => {
            switch(event_type)
            {
                case FileMonitorEvent.CREATED:
                    stdout.printf("'"+file.get_basename()+"' created"+"\n");
                    break;
                case FileMonitorEvent.DELETED:
                    stdout.printf("'"+file.get_basename()+"' deleted"+"\n");
                    break;    
            }
            stdout.flush();
        });
    } catch(Error e){
        stderr.printf("Could not create the monitor: "+e.message+"\n");
        return 1;
    }
    
    loop.run();
    
    return 0;
}
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to