Skip to content

FileAgeSecs (file age in seconds)

ts
function FileAgeSecs(path: string): number;

NOTE

This function is available as of Syncplify Server! v7.1.1. If you are running an older version, upgrade to v7.1.1 or later to use it.

Returns the number of seconds that have elapsed since the file at path was last modified. This is useful for determining whether a file is "fresh" or "stale" before processing it.

ParameterTypeRequirementExplanation
pathstringrequiredFully qualified path to the file
Return valueExplanation
number (≥ 0)Seconds elapsed since the file was last modified
-1The file does not exist or cannot be stat'd

Example

ts
var age = FileAgeSecs('/var/inbox/report.csv');
if (age < 0) {
  Log('File does not exist.');
} else if (age < 60) {
  Log('File was modified less than a minute ago; still writing?');
} else {
  Log('File is ready for processing.');
}

TIP

Combine FileAgeSecs with WaitForFile to ensure a file is completely written before processing it:

ts
// Wait until the file exists, then wait until it has not been modified for 10 seconds
if (WaitForFile('/var/inbox/upload.dat', 30000)) {
  while (FileAgeSecs('/var/inbox/upload.dat') < 10) {
    Sleep(1000);
  }
  // safe to process
}