2 Replies Latest reply on May 9, 2012 1:32 AM by Oleg Protokolov

    PSL file command ?

      Hi all,


      I'm writing a simple KM to monitor the age of a file in a directory on a windows server.

      The PSL code is really simple and I get a very strange result from the file() call.


      The file is created today:


      Volymens serienummer är AC7E-D7DB


      Innehåll i katalogen C:\tmp


      2012-05-07  20:58    <KAT>          .

      2012-05-07  20:58    <KAT>          ..

      2012-05-08  10:30                81 CTX.DAT


      The current time is 10:35.


      But the PSL code:




      print("Tid: ".age."\n");


      gives me:

      Tid: 22274429.3500000


      I thought the file() command should return the number of seconds since the file was created ?

      And the current time, minus the creation time of the file should give me the age of the file.

      Is there something I have overlooked ?

      Is the file() command not doing what it is supposed to do ?


      Any clues ?



        • 1. Re: PSL file command ?
          Jonathan Coop

          Yes the problem is the separator you've used for the filepath, a \ is in c language means escape the next character, example \n means a new line.



          So you MUST double up the backslashes or use forward slashes (yes it will work on windows).


          You've got the number of minutes since the 1st January 1970.


          Here is my example that works:





          print("Age of file is ".((timeNow-fileTime)/60)."\n");



          • 2. Re: PSL file command ?
            Oleg Protokolov

            Johan, Hi!

            Johan Landerholm wrote:



            I thought the file() command should return the number of seconds since the file was created ?


            For creation time of a file, you need use flag [enhanced] of a PSL-function file, and then extract the 3-rd argument from results (for details see "PATROL Script Language Reference Manual Volume 2—PSL Functions" ).

            file( filename, [enhanced] )


            For your case, with additions of Jon, the resulting code might be:


            fpath    = "c:\\tmp\\CTX.DAT";

            tid      = time();

            fctime   = ntharg( file( fpath, 1 ), 3, " " );

            if ( "" == fctime )


              printf("[ERROR] Can't find '%s'\n", fpath );



            fage_sec = tid - fctime;

            fage_min = fage_sec / 60;

            printf( "[INFO] File Age: %d mins (ctime: %s)\n", fage_min, asctime( fctime ) );


            Hope it helps...





            1 of 1 people found this helpful