PascalScript

This rule uses Delphi/Pascal programming syntax and conventions. Changes to the FileName variable will be treated as changes to the New Name of the File. Changes to the FilePath variable will not affect anything. Main code must be within the "begin" and "end." tags. User defined procedures, functions, variables, constants and types are supported, as well as importing of external functions from DLLs. Do not override registered variables, types and functions listed below. Some of the functions able to alter your file system, use those with caution! All FileName manipulations should be done with Unicode functions, i.e. WideString type should be used instead of an ordinary string type.

Registered Variables:

- FileName: WideString;
  filename of the currently processing file, including extension (e.g. "file.txt");
- FilePath: WideString;
  full path of the currently processing file (e.g. "c:\temp\file.txt");

Registered Types:

- TDateTime = Double;
  used for manipulating date and time values.
- TStringsArray = array of WideString;
  used for storing and manipulating lists of strings.

Registered Functions:

    *** String Handling Routines ***
    procedure Insert(Source: string; var S: string; Index: Integer);
    procedure Delete(var S: string; Index, Count: Integer);
    procedure SetLength(var S: string; NewLength: Integer);
    function Length(const S: string): Integer;
    function Copy(S: string; Index, Count: Integer): string;
    function Pos(Substr: string; S: string): Integer;

    *** Unicode String Handling Routines ***
    procedure WideInsert(const Substr: WideString; var Dest: WideString; Index: Integer);
    procedure WideDelete(var S: WideString; Index, Count: Integer);
    procedure WideSetLength(var S: WideString; NewLength: Integer);
    function WideLength(const S: WideString): Integer;
    function WideCopy(const S: WideString; Index, Count: Integer): WideString;
    function WidePos(const SubStr, S: WideString): Integer;
    function WidePosEx(const SubStr, S: WideString; Offset: Cardinal): Integer;
    function WideUpperCase(const S: WideString): WideString;
    function WideLowerCase(const S: WideString): WideString;
    function WideCompareStr(const S1, S2: WideString): Integer;
    function WideCompareText(const S1, S2: WideString): Integer;
    function WideSameText(const S1, S2: WideString): Boolean;
    function WideTextPos(const SubStr, S: WideString): Integer;

    *** TStringsArray Handling Routines ***
    function WideSplitString(const Input, Delimiter: WideString): TStringsArray;
    function WideArrayLength(const S: TStringsArray): Integer;
    procedure WideArraySetLength(var S: TStringsArray; NewLength: Integer);

    *** Unicode Character Handling Routines ***
    function IsWideCharUpper(WC: WideChar): Boolean;
    function IsWideCharLower(WC: WideChar): Boolean;
    function IsWideCharDigit(WC: WideChar): Boolean;
    function IsWideCharSpace(WC: WideChar): Boolean;
    function IsWideCharPunct(WC: WideChar): Boolean;
    function IsWideCharCntrl(WC: WideChar): Boolean;
    function IsWideCharBlank(WC: WideChar): Boolean;
    function IsWideCharXDigit(WC: WideChar): Boolean;
    function IsWideCharAlpha(WC: WideChar): Boolean;
    function IsWideCharAlphaNumeric(WC: WideChar): Boolean;
    function WideGetChar(const S: WideString; Index: Integer): WideChar;

    *** Unicode Conversion Routines ***
    function WideToAnsi(const WS: WideString): string;
    function AnsiToWide(const S: string): WideString;
    function UTF8Encode(const WS: WideString): string;
    function UTF8Decode(const S: string): WideString;

    *** Conversion Routines ***
    function IntToStr(Value: Integer): string;
    function StrToInt(const S: string): Integer;
    function StrToIntDef(const S: string; const Default: Integer): Integer;
    function DateToStr(D: TDateTime): string;
    function StrToDate(const S: string): TDateTime;

    *** Date And Time Routines ***
    function Date: TDateTime;
    function Time: TDateTime;
    function Now: TDateTime;
    function EncodeDate(Year, Month, Day: Word): TDateTime;
    function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
    function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean;
    function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean;
    procedure DecodeDate(const DateTime: TDateTime; var Year, Month, Day: Word);
    procedure DecodeTime(const DateTime: TDateTime; var Hour, Min, Sec, MSec: Word);
    function DayOfWeek(const DateTime: TDateTime): Word;
    function DateTimeToUnix(D: TDateTime): Int64;
    function UnixToDateTime(U: Int64): TDateTime;
    function FormatDateTime(const fmt: string; D: TDateTime): string;

    *** File Management Routines ***
    function WideFileSize(const FileName: WideString): Int64;
    function WideFileExists(const FileName: WideString): Boolean;
    function WideDirectoryExists(const Directory: WideString): Boolean;
    function WideForceDirectories(Dir: WideString): Boolean;
    function WideCreateDir(const Dir: WideString): Boolean;
    function WideDeleteFile(const FileName: WideString): Boolean;
    function WideRenameFile(const OldName, NewName: WideString): Boolean;
    function WideFileSearch(const Name, DirList: WideString): WideString;
    function WideGetCurrentDir: WideString;
    function WideSetCurrentDir(const Dir: WideString): Boolean;

    *** File Name Utilities ***
    function WideExtractFilePath(const FileName: WideString): WideString;
    function WideExtractFileDir(const FileName: WideString): WideString;
    function WideExtractFileDrive(const FileName: WideString): WideString;
    function WideExtractFileName(const FileName: WideString): WideString;
    function WideExtractBaseName(const FileName: WideString): WideString;
    function WideExtractFileExt(const FileName: WideString): WideString;
    function WideChangeFileExt(const FileName, Extension: WideString): WideString;
    function WideExpandFileName(const FileName: WideString): WideString;
    function WideExtractRelativePath(const BaseName, DestName: WideString): WideString;
    function WideExtractShortPathName(const FileName: WideString): WideString;
    function WideIncludeTrailingPathDelimiter(const S: WideString): WideString;
    function WideExcludeTrailingPathDelimiter(const S: WideString): WideString;
    function WideSameFileName(const S1, S2: WideString): Boolean;
    procedure WideScanDir(const Dir: WideString; var Files: TStringsArray;
      const IncludeSubfolders, IncludeHiddenFiles: Boolean; const Mask: WideString);

    *** File Read/Write Routines ***
    function FileModifiedTime(const FileName: WideString): TDateTime;
    function FileCreatedTime(const FileName: WideString): TDateTime;
    function FileReadLine(const FileName: WideString; LineNum: Integer): string;
    function FileCountLines(const FileName: WideString): Integer;
    function FileReadContent(const FileName: WideString): string;
    procedure FileWriteContent(const FileName: WideString; const Content: string);

    *** Process Execution Routines ***
    function ExecuteProgram(const Command: string; WaitForProgram: Boolean): Cardinal;
    function ExecConsoleApp(const CommandLine: string; out Output: string): Cardinal;

    *** Other Routines ***
    procedure Randomize;
    procedure Sleep(Milliseconds: Cardinal);
    procedure WideShowMessage(const Msg: WideString);
    procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: Word);
    function RandomRange(const AFrom, ATo: Integer): Integer;
    function GetTickCount: Cardinal;
    function SizeOf(X): Integer;

More Information:

www.delphibasics.co.uk
www.remobjects.com