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

PSL file command ?

Johan Landerholm

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:

dir

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:

 

tid=time();

age=((tid-file("c:\tmp\CTX.DAT"))/60);'

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 ?

 

/Johan

  • 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:

     

     

    timeNow=time();

    fileTime=file("C:\\hlo\\helloworld.txt");

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

     

    Jon

  • 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 );

      exit;

    }

    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...

     

    --

    Regards,

    Oleg