Re: [Vala] Get CREATION DATE OR TIME of file



It's not currently possible to do that on most systems, take a look at File creation times [LWN.net]
|   |
|   |   |   |   |   |
| File creation times [LWN.net]By Jonathan Corbet July 26, 2010 Linux systems, like the Unix systems that 
came before, maintain threedifferent timestamps for each file.  |
|  |
| Ver en lwn.net | Vista previa por Yahoo |
|  |
|   |


 
Mario Daniel Ruiz Saavedra  Estudiante Ing. Sistemas - Universidad del Norte mruizd uninorte edu co - 
twitter.com/desiderantes -
joindiaspora.com/u/desiderantes 

    El Sábado, 9 de enero, 2016 8:34:17, raum <raum no-log org> escribió:
 
 

 Hi,

Problem between windows and linux API,  probably...

Either you can take a look to one of my project wich worked on linux

https://github.com/Raumy/check_fs

Regards
Le 9 janv. 2016 10:30, Chris Daley <chebizarro gmail com> a écrit :

Hi all,

One possible solution to this problem that would be Windows only is to
retrieve the file creation date via the Windows API. The following code is
untested as I am still setting up my Winodws VM but you might be able to
try it out in the meantime. You will need to install the Windows SDK if you
haven't already and I assume you are using mingw. A caveat, I haven't used
the Windows API in a long time so you may need to double check the headers
to make sure the function definitions are correct - this is for version
7.0. I'm assuming it's possible, as the parts of the Windows API you would
be linking to are C libraries and this is more or less how you would do it
in C# but like I said - this is an untested thought experiment that might
be a total NO-OP. The only thing I could find on the internets was from the
mailing list quite a few years back -
http://comments.gmane.org/gmane.comp.programming.vala/2867 - but it does
suggest that this is entirely possible.

Anyway, the code...

// All of this is Windows API definitions which could be put into a
separate vapi

// The CreateFile flag for reading
const int64 GENERIC_READ = 0x80000000;

// Contains a 64-bit value representing the number of 100-nanosecond
intervals since January 1, 1601 (UTC).
struct FileTime {
    // The low-order part of the file time.
    int64 dwLowDateTime;
    // The high-order part of the file time.
    int64 dwHighDateTime;
}

struct SystemTime {
   int64 wYear;
   int64 wMonth;
   int64 wDayOfWeek;
   int64 wDay;
   int64 wHour;
   int64 wMinute;
   int64 wSecond;
   int64 wMilliseconds;
}

[CCode(cheader_filename = "WinBase.h ")]
public extern bool GetFileTime(void* file_handle,
    out lpCreationTime,
    out lpLastAccessTime,
    out lpLastWriteTime
);

[CCode(cheader_filename = "WinBase.h ")]
public extern void CreateFile(
    string lpFileName,
    int64 dwDesiredAccess,
    int64 dwShareMode,
    void* lpSecurityAttributes,
    int64 dwCreationDisposition,
    int64 dwFlagsAndAttributes,
    void* hTemplateFile
);

[CCode(cheader_filename = "WinBase.h ")]
public extern bool FileTimeToSystemTime (FileTime filetime, out SystemTime);

public static int main (string[] args) {

   void* testfile = CreateFile("./test.vala", GENERIC_READ,0, null, 0, 0,
null);
   FileTime time;
   bool success = GetFileTime(testfile,out time, null, null);

    if (success) {
       SystemTime systime;
       FileTimeToSystemTime (time, out systime);
       message ("Success: File created on %02d/%02d/%d %02d:%02d",
systime.wMonth, systime.wDay, systime.wYear, systime.wHour,
systime.wMinute);
    } else {
      message ("Something went wrong");
   }
}

This would need to be compiled with the right paths set to the Windows SDK
location and linked against Kernel32.lib.

Like I said, it's untested (yet) and I won't have time until next week to
look at it again, so caveat emptor. If you're wanting to make a nicer
demonstration out of it, you could save the Windows extern functions and
struct definitions to a vapi file - like windows.vapi - to make it look
less complicated (which it is, compared to the C code that would achieve
the same effect).

Let me know if you have any success.

Cheers
Chris

2016-01-08 12:35 GMT-08:00 Edwin De La Cruz <edwinspire gmail com>:

Lametablemente no way? At least not directly using Vala , I understand
what I have read so far.
I keep looking for any option , since it was very important for me to
do in Vala and convince some people that language worth learning ...
I'll keep looking.
Mis proyectos de software libre en:
Github - edwinspire


2016-01-08 9:04 GMT-05:00 Luc Chante <luc chante gmail com>:
Hi,

You can test le file a attached to this mail.

T
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list


 
  


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