Get the newest file in a directory



Hi all,

in shell extension I'll try to determine the newest file present in a directory.

I have used this code:

    let dir = Gio.file_new_for_path(bookmarkDir);
var backupEnum = dir.enumerate_children('standard::name,standard::type,time::modified', Gio.FileQueryInfoFlags.NONE, null);

    let infoTimeVal = new GLib.TimeVal();
    let max = 0;
    let info;

    while ((info = backupEnum.next_file(null)) != null) {
       let type = info.get_file_type();
        if (type == Gio.FileType.REGULAR) {

          info.get_modification_time(infoTimeVal);

          if (infoTimeVal.tv_sec > max) {
            max = infoTimeVal.tv_sec;
             var lastFile = info;
          }
        }
    }
    backupEnum.close(null);

I my system (F16) it works correctly, but in a Debian (I don't know version) the command info.get_modification_time(infoTimeVal) return zero in infoTimeVal.tv_sec variable.

There is something I'm missing? Can I obtain the same results in other ways.

Thanks.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]