# Pascal Script

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);
    function Copy(S: string; Index, Count: Integer): string;
    function Pos(Substr: string; S: string): Integer;

    *** Length Managing Routines ***
    procedure SetLength(var S: array; NewLength: Integer);
    procedure SetLength(var S: string; NewLength: Integer);
    procedure SetLength(var S: WideString; NewLength: Integer);
    function Length(const S: array): Integer;
    function Length(const S: string): Integer;
    function Length(const S: WideString): 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;
    function WideTrim(const S: WideString): WideString;
    function WideReplaceStr(const S, OldPattern, NewPattern: WideString): WideString;
    function WideReplaceText(const S, OldPattern, NewPattern: WideString): WideString;
    function WideSplitString(const Input, Delimiter: WideString): TStringsArray;
    function WideCaseCapitalize(const S: WideString): WideString;
    function WideCaseInvert(const S: WideString): WideString;

    *** Meta Tags Extraction ***
    function CalculateMetaTag(const FilePath: WideString; const MetaTagName string): string;

    *** Regular Expressions ***
    function ReplaceRegEx(const Input, Find, Replace: WideString; const CaseSensitive, UseSubstitution: Boolean): WideString;
    function MatchesRegEx(const Input, Find: WideString; const CaseSensitive: Boolean): TStringsArray;

    *** 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;

    *** 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;
    function Chr(X: Byte): Char;
    function Ord(X: Char): Byte;

    *** 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;
    procedure WideScanDirForFiles(Dir: WideString; var Files: TStringsArray;
      const Recursive, IncludeHidden, IncludeSystem: Boolean; const Mask: WideString);
    procedure WideScanDirForFolders(Dir: WideString; var Folders: TStringsArray;
      const Recursive, IncludeHidden, IncludeSystem: 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 WideStripExtension(const FileName: 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;

    *** File Read/Write Routines ***
    function FileReadFragment(const FileName: WideString; Start, Length: Integer): string;
    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);

    *** File Properties Routines ***
    function FileTimeModified(const FileName: WideString): TDateTime;
    function FileTimeCreated(const FileName: WideString): TDateTime;
    function SetFileTimeCreated(const FileName: WideString; const DateTime: TDateTime): Boolean;
    function SetFileTimeModified(const FileName: WideString; const DateTime: TDateTime): Boolean;

    *** 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 ShowMessage(const Msg: string);
    procedure WideShowMessage(const Msg: WideString);
    procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: Word);
    procedure SetClipboardText(const S: WideString);
    function GetClipboardText: WideString;
    function RandomRange(const AFrom, ATo: Integer): Integer;
    function GetTickCount: Cardinal;
    function SizeOf(X): Integer;

More Information:

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