PilotScript File Functions

The following file functions are available for PilotScript components.

The File functions operation on file system objects, but do not process the content of files.

File Function Name/Prototype Description Example

FileChecksum

String FileChecksum(String filepath)
Returns a number which is a MD5 checksum for the contents of the file. This is an excellent way to compare two files to see if they are identical. (The chances of random collision for different files is extremely small.)
IF (FileChecksum(#file1) !== FileChecksum(#file2))
 THEN
   /* Files are not equal */
   .. do something ..

END IF;

Perform an action if the files are not the same.

FileDelete

Boolean FileDelete(String filename)
Tries to delete the given server file. Returns True if successful.
FileDelete(#tempFile);

Deletes the given temporary file.

FileExists

Boolean FileExists(String filename)
Returns True if the given file (passed in as a string) exists on the server. The function supports path specification for files on the local file system or on the local network.
IF (NOT FileExists(@jobdir.'/result100.smx'))
 THEN
   Error("Did not find the needed results file");

END IF;

Throws an error if a particular file is not found in the job directory of the server.

FileLastModified

Date FileLastModified(String filename)
Returns a date/time value containing the last modification time of the given file (if that information is available on the particular operating system). If the file is not found, Julian time 0 is returned.
#mod := FileLastModified(@jobdir.'/result100.smx');

IF (DateJulian(#mod) <= 0)
 THEN
   Error("Did not find needed results file");

ELSIF (DateDaysBetween(DateCurrent(), #mod) > 7)
 THEN 
   Error("Results file is older than a week");

END IF;

Gets the last modification date, then checks if the file does not exist or is too old to use.

FileOwner

String FileOwner(String filename)
Returns the owner of the file. If the file does not exist, an empty string is returned.
#file := @jobdir.'/result100.smx';

IF (FileOwner(#file) ne '$(Username)')
 THEN
   Error(Format("You do not own file %s", #file));

END IF;

Throws an error if the file is not owned by the person running the protocol.

FileRename

Boolean FileRename(String filename, String newfilename)
Tries to rename the given server file to another name. Returns True if successful.
FileRename(#tempFile, #permanantFile);

Renames the given temp file to a permanent name.

FileSize

Number FileSize(String filename)
Returns the size of the server file, in bytes. If the file does not exist on the server, -1 is returned. (The maximum file size that can be returned is 232 or 4 GB)
#Size := FileSize(#file);

Scale := 'Small';

IF (#Size > 100000000)
 THEN
   Scale := 'HUGE';

ELSIF (#Size > 1000000)
 THEN
   Scale := 'Big';

END IF;

Creates a property Scale that is set to either "Small", "Big", or "HUGE", depending on the size of the file.