Difference between revisions of "ReNamer:Pascal Script:Functions"
(Add WideString array handling functions) |
|||
(90 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{Go|up=ReNamer:Pascal Script|prev=ReNamer:Pascal Script:Types}} |
ReNamer has many functions to manipulate the entities related to file names and do some more complex tasks for individual files. These entities may be derived from the existing filename, path, system date, meta tags from the file, strings entered by the user, etc. This functionality is available for use via the [[ReNamer:Rules:PascalScript|PascalScript rule]]. | ReNamer has many functions to manipulate the entities related to file names and do some more complex tasks for individual files. These entities may be derived from the existing filename, path, system date, meta tags from the file, strings entered by the user, etc. This functionality is available for use via the [[ReNamer:Rules:PascalScript|PascalScript rule]]. | ||
− | A common prefix | + | The difference between a "function" and a "procedure" is that while a function executes an algorithm and returns a value, a procedure just executes an algorithm without returning anything. |
+ | |||
+ | A common "Wide" prefix in function names indicates that the function deals with '''WideString''' type rather than '''AnsiString''' or '''String''' type. For example, ''ShowMessage'' and ''WideShowMessage'' procedures. See the [[ReNamer:Pascal_Script:Types#String_types|String Types]] for more information. | ||
== Basic String Handling == | == Basic String Handling == | ||
Line 26: | Line 28: | ||
'''Note:''' Indexes of characters in strings are 1 based, so first character in string S would be S[1]. | '''Note:''' Indexes of characters in strings are 1 based, so first character in string S would be S[1]. | ||
+ | |||
+ | {{Top}} | ||
== Length Management == | == Length Management == | ||
Line 53: | Line 57: | ||
|} | |} | ||
− | == | + | {{Top}} |
+ | |||
+ | == Wide String Handling == | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 65: | Line 71: | ||
| procedure '''WideDelete'''(var S: WideString; Index, Count: Integer); | | procedure '''WideDelete'''(var S: WideString; Index, Count: Integer); | ||
| Deletes '''Count''' characters from '''S''', starting from the '''Index''' position. | | Deletes '''Count''' characters from '''S''', starting from the '''Index''' position. | ||
+ | |- | ||
+ | | procedure '''WideDeleteRight'''(var S: WideString; Index, Count: Integer); | ||
+ | | Delete '''Count''' characters from '''S''', starting from the '''Index''' position from the end and counting towards the start. | ||
+ | |||
+ | ''Added in v6.0.0.9 Alpha.'' | ||
|- | |- | ||
| procedure '''WideSetLength'''(var S: WideString; NewLength: Integer); | | procedure '''WideSetLength'''(var S: WideString; NewLength: Integer); | ||
Line 73: | Line 84: | ||
|- | |- | ||
| function '''WideCopy'''(const S: WideString; Index, Count: Integer): WideString; | | function '''WideCopy'''(const S: WideString; Index, Count: Integer): WideString; | ||
− | | Returns '''Count''' characters from WideString '''S''', starting at position '''Index'''. | + | | Returns '''Count''' characters from '''S''', starting at position '''Index'''. |
+ | |- | ||
+ | | function '''WideCopyRight'''(const S: WideString; Index, Count: Integer): WideString; | ||
+ | | Returns '''Count''' characters from '''S''', starting at position '''Index''' from the end and counting towards the start. | ||
+ | |||
+ | ''Added in v6.0.0.9 Alpha.'' | ||
|- | |- | ||
| function '''WidePos'''(const SubStr, S: WideString): Integer; | | function '''WidePos'''(const SubStr, S: WideString): Integer; | ||
Line 98: | Line 114: | ||
| function '''WideTextPos'''(const SubStr, S: WideString): Integer; | | function '''WideTextPos'''(const SubStr, S: WideString): Integer; | ||
| Behaves like '''WidePos''' function, except text if processed in case-insensitive manner. | | Behaves like '''WidePos''' function, except text if processed in case-insensitive manner. | ||
+ | |- | ||
+ | | function '''WideTextPosEx'''(const SubStr, S: WideString; Offset: Cardinal): Integer; | ||
+ | | Behaves like '''WidePosEx''' function, except text if processed in case-insensitive manner. | ||
+ | |||
+ | ''Added in v6.6.0.1 Beta.'' | ||
|- | |- | ||
| function '''WideTrim'''(const S: WideString): WideString; | | function '''WideTrim'''(const S: WideString): WideString; | ||
| Removes leading and trailing spaces and control characters from the given string '''S'''. | | Removes leading and trailing spaces and control characters from the given string '''S'''. | ||
+ | |- | ||
+ | | function '''WideTrimChars'''(const S, CharsToTrim: WideString): WideString; | ||
+ | | Remove characters that occur in '''CharsToTrim''' from the beginning and the end of '''S'''. | ||
+ | |||
+ | ''Added in v6.0.0.9 Alpha.'' | ||
+ | |- | ||
+ | | function '''WideTrimCharsLeft'''(const S, CharsToTrim: WideString): WideString; | ||
+ | | Remove characters that occur in '''CharsToTrim''' from the beginning of '''S'''. | ||
+ | |||
+ | ''Added in v6.0.0.9 Alpha.'' | ||
+ | |- | ||
+ | | function '''WideTrimCharsRight'''(const S, CharsToTrim: WideString): WideString; | ||
+ | | Remove characters that occur in '''CharsToTrim''' from the end of '''S'''. | ||
+ | |||
+ | ''Added in v6.0.0.9 Alpha.'' | ||
+ | |- | ||
+ | | function '''WideReverseString'''(const S: WideString): WideString; | ||
+ | | Return a reversed version of string '''S''', i.e. reverse the order of characters. | ||
+ | |||
+ | ''Added in v6.7.0.4 Beta.'' | ||
+ | |- | ||
+ | | function '''WideRepeatString'''(const S: WideString; Count: Integer): WideString; | ||
+ | | Repeat a string a number of times.<br/>''Added in v6.9.0.3 Beta.'' | ||
+ | |||
|- | |- | ||
| function '''WideReplaceStr'''(const S, OldPattern, NewPattern: WideString): WideString; | | function '''WideReplaceStr'''(const S, OldPattern, NewPattern: WideString): WideString; | ||
− | | | + | | Return a result of a ''case-sensitive'' replacement of all occurrences of '''OldPattern''' with '''NewPattern''' in a string '''S'''. |
+ | |||
|- | |- | ||
| function '''WideReplaceText'''(const S, OldPattern, NewPattern: WideString): WideString; | | function '''WideReplaceText'''(const S, OldPattern, NewPattern: WideString): WideString; | ||
− | | | + | | Return a result of a ''case-insensitive'' replacement of all occurrences of '''OldPattern''' with '''NewPattern''' in a string '''S'''. |
|- | |- | ||
− | | function '''WideSplitString'''(const Input, Delimiter: WideString): | + | | function '''WideSplitString'''(const Input, Delimiter: WideString): TWideStringArray; |
| | | | ||
− | Splits the | + | Splits the '''Input''' wherever '''Delimiter''' occurs and returns an array that contains the split parts. |
− | *The '''Delimiter''' itself can be a multi-character WideString. <br>(Unlike the usual comma, hyphen or space that | + | *The '''Delimiter''' itself can be a multi-character WideString. <br>(Unlike the usual comma, hyphen or space that are used for this purpose) |
− | *The split parts (returned as elements of the array) do not contain the '''Delimiter''' | + | *The split parts (returned as elements of the array) do not contain the '''Delimiter'''. |
|- | |- | ||
− | | function ''' | + | |- |
− | | | + | | function '''WideJoinStrings'''(const Strings: TWideStringArray; const Delimiter: WideString): WideString; |
− | + | | Joins all individual items from '''Strings''' into a single WideString, with '''Delimiter''' inserted between the joined items. | |
− | + | |- | |
+ | | function '''WideCaseSentence'''(const S: WideString): WideString; | ||
+ | | Returns a ''Sentence case'' version of parameter '''S'''. | ||
− | + | Only the first alphabetic character is capitalized. All other alphabetic characters are converted to lowercase. | |
+ | ''Added in v6.0.0.3 Alpha''. | ||
|- | |- | ||
− | | function ''' | + | | function '''WideCaseCapitalize'''(const S: WideString): WideString; |
− | | | + | | |
− | + | Returns the ''Title case'' version of parameter '''S'''. | |
− | + | First letter of every word is capitalized. All other alphabetic characters are converted to lowercase. | |
− | |||
|- | |- | ||
− | + | | function '''WideCaseInvert'''(const S: WideString): WideString; | |
− | + | | Inverts case of all characters in '''S''' and returns it. | |
− | |||
− | | function ''' | ||
− | | | ||
|} | |} | ||
− | + | {{Top}} | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | + | == Wide String Array Handling == |
{| class="wikitable" | {| class="wikitable" | ||
Line 156: | Line 194: | ||
! Remarks | ! Remarks | ||
|- | |- | ||
− | | | + | | procedure '''WideAppendStringArray'''(var Strings: TWideStringArray; const NewString: WideString); |
− | | | + | | Add a WideString to the end of a WideString array.<br/>''Added in v7.5.0.3 Beta.'' |
|- | |- | ||
− | | function ''' | + | | function '''WideCopyStringArray'''(const Strings: TWideStringArray; Index, Count: Integer): TWideStringArray; |
− | | | + | | Copy a portion of a WideString array by taking '''Count''' elements starting from '''Index''' position.<br/>''Added in v7.5.0.3 Beta.'' |
− | |||
− | |||
|- | |- | ||
− | | function ''' | + | | function '''WideConcatStringArrays'''(const A, B: TWideStringArray): TWideStringArray; |
− | | | + | | Concatenate two WideString arrays.<br/>''Added in v7.5.0.3 Beta.'' |
− | |||
− | |||
− | |||
− | |||
|} | |} | ||
− | + | {{Top}} | |
− | + | == Wide Character Handling == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 188: | Line 214: | ||
|- | |- | ||
| function '''IsWideCharUpper'''(WC: WideChar): Boolean; | | function '''IsWideCharUpper'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is in upper case. |
|- | |- | ||
| function '''IsWideCharLower'''(WC: WideChar): Boolean; | | function '''IsWideCharLower'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is in lower case. |
|- | |- | ||
| function '''IsWideCharDigit'''(WC: WideChar): Boolean; | | function '''IsWideCharDigit'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a digit (numeric character 0-9). |
|- | |- | ||
| function '''IsWideCharSpace'''(WC: WideChar): Boolean; | | function '''IsWideCharSpace'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a white-space character, such as: space, form-feed, newline, carriage-return, tab and vertical-tab (characters classified as C1_SPACE). |
|- | |- | ||
| function '''IsWideCharPunct'''(WC: WideChar): Boolean; | | function '''IsWideCharPunct'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a punctuation mark (characters classified as C1_PUNCT). |
|- | |- | ||
| function '''IsWideCharCntrl'''(WC: WideChar): Boolean; | | function '''IsWideCharCntrl'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a control character (characters classified as C1_CNTRL). |
|- | |- | ||
| function '''IsWideCharBlank'''(WC: WideChar): Boolean; | | function '''IsWideCharBlank'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a blank, such as: space and tab (characters classified as C1_BLANK). |
|- | |- | ||
| function '''IsWideCharXDigit'''(WC: WideChar): Boolean; | | function '''IsWideCharXDigit'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a hexadecimal digit (0-9 or A-F). |
|- | |- | ||
| function '''IsWideCharAlpha'''(WC: WideChar): Boolean; | | function '''IsWideCharAlpha'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a alphanumeric character (a-z or A-Z). |
|- | |- | ||
| function '''IsWideCharAlphaNumeric'''(WC: WideChar): Boolean; | | function '''IsWideCharAlphaNumeric'''(WC: WideChar): Boolean; | ||
− | | Checks | + | | Checks character '''WC''' and returns TRUE if it is a alphanumeric character or a numeric character (a-z, A-Z or 0-9). |
+ | |- | ||
+ | | function '''IsWideWordBoundaryLeft'''(const Subject: WideString; CharPosition: Integer): Boolean; | ||
+ | | Check if a character at the specified position is on a word boundary to the left. | ||
+ | |||
+ | Conditions that qualify as word boundaries to the left of character: | ||
+ | # If first character and is a word character. | ||
+ | # Between word and not a word character. | ||
+ | |||
+ | ''Added in v6.6.0.1 Beta.'' | ||
+ | |- | ||
+ | | function '''IsWideWordBoundaryRight'''(const Subject: WideString; CharPosition: Integer): Boolean; | ||
+ | | Check if a character at the specified position is on a word boundary to the right. | ||
+ | |||
+ | Conditions that qualify as word boundaries to the right of character: | ||
+ | # If last character and is a word character. | ||
+ | # Between word and not a word character. | ||
+ | |||
+ | ''Added in v6.6.0.1 Beta.'' | ||
|- | |- | ||
| function '''WideCharUpper'''(const WC: WideChar): WideChar; | | function '''WideCharUpper'''(const WC: WideChar): WideChar; | ||
− | | Returns | + | | Returns an upper case version of the input character. In case of non-alphabetic character, it returns the same character. |
|- | |- | ||
| function '''WideCharLower'''(const WC: WideChar): WideChar; | | function '''WideCharLower'''(const WC: WideChar): WideChar; | ||
− | | Returns a | + | | Returns a lower case version of the input character. In case of non-alphabetic character, it returns the same character. |
+ | |- | ||
+ | | function '''WideChr'''(Code: Word): WideChar; | ||
+ | | Create a character from a code point.<br/>''Added in v6.9.0.3 Beta.'' | ||
|} | |} | ||
'''Note:''' Character classifications, such as C1_UPPER, C1_LOWER, C1_DIGIT, C1_SPACE, C1_PUNCT, C1_CNTRL, C1_BLANK, C1_XDIGIT, C1_ALPHA - are part of Unicode definitions. More information regarding classification can be found on the internet. For example: [http://www.fileformat.info/info/unicode/ http://www.fileformat.info/info/unicode/]. | '''Note:''' Character classifications, such as C1_UPPER, C1_LOWER, C1_DIGIT, C1_SPACE, C1_PUNCT, C1_CNTRL, C1_BLANK, C1_XDIGIT, C1_ALPHA - are part of Unicode definitions. More information regarding classification can be found on the internet. For example: [http://www.fileformat.info/info/unicode/ http://www.fileformat.info/info/unicode/]. | ||
+ | |||
+ | {{Top}} | ||
== Unicode Conversion == | == Unicode Conversion == | ||
Line 234: | Line 283: | ||
|- | |- | ||
| function '''WideToAnsi'''(const WS: WideString): String; | | function '''WideToAnsi'''(const WS: WideString): String; | ||
− | | | + | | Convert WideString type to AnsiString type.<br/>In v7.0 and later, this conversion is performed automatically on assignment. |
|- | |- | ||
| function '''AnsiToWide'''(const S: String): WideString; | | function '''AnsiToWide'''(const S: String): WideString; | ||
− | | | + | | Convert AnsiString type to WideString type.<br/>In v7.0 and later, this conversion is performed automatically on assignment. |
|- | |- | ||
| function '''UTF8Encode'''(const WS: WideString): String; | | function '''UTF8Encode'''(const WS: WideString): String; | ||
− | | Convert | + | | Convert WideString type to UTF-8 encoded string. |
|- | |- | ||
| function '''UTF8Decode'''(const S: String): WideString; | | function '''UTF8Decode'''(const S: String): WideString; | ||
− | | Convert [ | + | | Convert UTF-8 encoded string to WideString type. |
+ | |- | ||
+ | | function '''WinCPToUTF8'''(const S: String): String; | ||
+ | | Convert a string encoded with active [https://en.wikipedia.org/wiki/Windows_code_page system code page] to a UTF-8 encoded string.<br/>Added in v7.4.0.3 Beta. | ||
+ | |- | ||
+ | | function '''UTF8ToWinCP'''(const S: String): String; | ||
+ | | Convert a UTF-8 encoded string to a string encoded with active [https://en.wikipedia.org/wiki/Windows_code_page system code page].<br/>Added in v7.4.0.3 Beta. | ||
|} | |} | ||
+ | |||
+ | See [[ReNamer:Pascal_Script:Types#String_types|String types]] for additional information on the default encoding and conversion procedures. | ||
+ | |||
+ | == Console Output Conversion == | ||
+ | |||
+ | OEM-defined character set is commonly used in the output of console applications. | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Function | ||
+ | ! Remarks | ||
+ | |- | ||
+ | | function '''OemToAnsi'''(const S: String): String; | ||
+ | | Convert OEM string into an ANSI string.<br/>''Added in v6.6.0.2 Beta.'' | ||
+ | |- | ||
+ | | function '''OemToWide'''(const S: String): WideString; | ||
+ | | Convert OEM string into a WideString.<br/>''Added in v6.6.0.2 Beta.'' | ||
+ | |- | ||
+ | | function '''AnsiToOem'''(const S: String): String; | ||
+ | | Convert ANSI string into an OEM string.<br/>''Added in v6.6.0.2 Beta.'' | ||
+ | |- | ||
+ | | function '''WideToOem'''(const S: WideString): String; | ||
+ | | Convert WideString into an OEM string.<br/>''Added in v6.6.0.2 Beta.'' | ||
+ | |} | ||
+ | |||
+ | {{Top}} | ||
== Basic Conversion == | == Basic Conversion == | ||
Line 254: | Line 335: | ||
|- | |- | ||
| function '''BoolToStr'''(B: Boolean): String; | | function '''BoolToStr'''(B: Boolean): String; | ||
− | | Convert boolean variable into a string. Returns | + | | Convert boolean variable into a string. Returns "''True''" or "''False''" string value. |
|- | |- | ||
| function '''IntToStr'''(Value: Integer): String; | | function '''IntToStr'''(Value: Integer): String; | ||
Line 263: | Line 344: | ||
* IntToStr(123) <> '0123' | * IntToStr(123) <> '0123' | ||
</div> | </div> | ||
+ | <b>Note:</b> Be cautious of supplying ''Int64'' type as a parameter as it will be type casted to ''Integer'', which significantly reduces the range of possible values (refer to [[ReNamer:Pascal Script:Types|Types]] for more information). You can use '''FormatFloat''' function to convert ''Int64'' values to a string without a loss of range. | ||
+ | |- | ||
+ | | function '''Int64ToStr'''(Value: Int64): String; | ||
+ | | Same as '''IntToStr''' but takes in ''Int64'' typed parameter. | ||
|- | |- | ||
| function '''StrToInt'''(const S: String): Integer; | | function '''StrToInt'''(const S: String): Integer; | ||
Line 272: | Line 357: | ||
</div> | </div> | ||
'''Warning:''' An error will occur if the parameter to this function cannot be converted to an integer! | '''Warning:''' An error will occur if the parameter to this function cannot be converted to an integer! | ||
+ | |- | ||
+ | | function '''StrToInt64'''(const S: String): Int64; | ||
+ | | Same as '''StrToInt''' but returns ''Int64'' typed result. | ||
|- | |- | ||
| function '''StrToIntDef'''(const S: String; const Default: Integer): Integer; | | function '''StrToIntDef'''(const S: String; const Default: Integer): Integer; | ||
| Behaves like '''StrToInt''' function, but instead of producing an error on incorrect input function allows the '''Default''' value to be specified, which will be returned if the input cannot be converted to an integer. | | Behaves like '''StrToInt''' function, but instead of producing an error on incorrect input function allows the '''Default''' value to be specified, which will be returned if the input cannot be converted to an integer. | ||
+ | |- | ||
+ | | function '''StrToInt64Def'''(const S: String; Default: Int64): Int64; | ||
+ | | Same as '''StrToIntDef''' but operates with ''Int64'' type. | ||
+ | |- | ||
+ | | function '''TryStrToInt'''(const S: String; out Value: Integer): Boolean; | ||
+ | | Converts a string to an integer, but does not throw an error when invalid string is supplied, unlike '''StrToInt'''. Returns ''False'' if conversion operation has failed. | ||
|- | |- | ||
| function '''FloatToStr'''(Value: Extended): string; | | function '''FloatToStr'''(Value: Extended): string; | ||
Line 286: | Line 380: | ||
|- | |- | ||
| function '''FormatFloat'''(const Format: string; Value: Extended): string; | | function '''FormatFloat'''(const Format: string; Value: Extended): string; | ||
− | | Converts supplied floating point value to its string representation, using user specific '''Format'''. | + | | Converts supplied floating point value to its string representation, using user specific '''Format'''.<br/>Check [[#Floating point format specifiers|floating point format specifiers]] below for more information. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | | | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| function '''DateToStr'''(D: TDateTime): String; | | function '''DateToStr'''(D: TDateTime): String; | ||
Line 322: | Line 400: | ||
| function '''HexToIntDef'''(const HexNum: String; Default: Integer): Integer; | | function '''HexToIntDef'''(const HexNum: String; Default: Integer): Integer; | ||
| Behaves like '''HexToInt''' function, but instead of producing an error on incorrect input function allows the '''Default''' value to be specified, which will be returned if the input cannot be converted to an integer. | | Behaves like '''HexToInt''' function, but instead of producing an error on incorrect input function allows the '''Default''' value to be specified, which will be returned if the input cannot be converted to an integer. | ||
+ | |- | ||
+ | | function '''IntToRoman'''(Value: Integer): String; | ||
+ | | Convert a decimal number to Roman numerals.<br/>''Added in v7.3.0.4 Beta.'' | ||
+ | |- | ||
+ | | function '''RomanToInt'''(const S: String): Integer; | ||
+ | | Convert Roman numerals to a decimal number.<br/>''Added in v7.3.0.4 Beta.'' | ||
+ | |- | ||
+ | | function '''RomanToIntDef'''(const S: String; Default: Integer): Integer; | ||
+ | | Convert Roman numerals to a decimal number. Returns the '''Default''' value in the conversion fails.<br/>''Added in v7.3.0.4 Beta.'' | ||
+ | |- | ||
+ | | function '''TryRomanToInt'''(const S: String; out Value: Integer): Boolean; | ||
+ | | Try to convert Roman numerals to a decimal number. Does not throw an error on failure, instead it returns ''False''.<br/>''Added in v7.3.0.4 Beta.'' | ||
|- | |- | ||
| function '''Ord'''(X: Char): Byte; | | function '''Ord'''(X: Char): Byte; | ||
Line 329: | Line 419: | ||
| Return a character by its ordinal value (byte representation). | | Return a character by its ordinal value (byte representation). | ||
|} | |} | ||
+ | |||
+ | === Floating point format specifiers === | ||
+ | |||
+ | {| class="wikitable" | ||
+ | ! Specifier | ||
+ | ! Represents | ||
+ | |- | ||
+ | | <tt>0</tt> (zero) | ||
+ | | Digit placeholder. If the value being formatted has a digit in the position where the "0" appears in the format string, then that digit is copied to the output string. Otherwise, a "0" is stored in that position in the output string. | ||
+ | |- | ||
+ | | <tt>#</tt> (hash) | ||
+ | | Digit placeholder. If the value being formatted has a digit in the position where the "#" appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string. | ||
+ | |- | ||
+ | | <tt>.</tt> (dot) | ||
+ | | Decimal point. The first "." character in the format string determines the location of the decimal separator in the formatted value, any additional "." characters are ignored. | ||
+ | |- | ||
+ | | <tt>,</tt> (comma) | ||
+ | | Thousand separator. If the format string contains one or more "," characters, the output will have thousand separators inserted between each group of three digits to the left of the decimal point. The placement and number of "," characters in the format string does not affect the output. | ||
+ | |} | ||
+ | |||
+ | {{Top}} | ||
== Date and Time == | == Date and Time == | ||
Line 351: | Line 462: | ||
| function '''EncodeTime'''(Hour, Min, Sec, MSec: Word): TDateTime; | | function '''EncodeTime'''(Hour, Min, Sec, MSec: Word): TDateTime; | ||
| Generates time value for the specified '''Hour''', '''Min''', '''Sec''', '''MSec'''. Parameters must be within a valid time range: Hour = 0..23, Min = 0..59, Sec = 0..59, MSec = 0..999. An error will be raised if parameters are invalid. | | Generates time value for the specified '''Hour''', '''Min''', '''Sec''', '''MSec'''. Parameters must be within a valid time range: Hour = 0..23, Min = 0..59, Sec = 0..59, MSec = 0..999. An error will be raised if parameters are invalid. | ||
+ | |- | ||
+ | | function '''EncodeDateTime'''(Year, Month, Day, Hour, Minute, Second, MilliSecond: Word): TDateTime; | ||
+ | | Generates date-time value for the specified components of date and time. Similar to '''EncodeDate''' and '''EncodeTime'''.<br/>''Added in v6.2.0.5 Beta.'' | ||
|- | |- | ||
| function '''TryEncodeDate'''(Year, Month, Day: Word; var Date: TDateTime): Boolean; | | function '''TryEncodeDate'''(Year, Month, Day: Word; var Date: TDateTime): Boolean; | ||
− | | Behaves exactly like '''EncodeDate''' function, except this function returns | + | | Behaves exactly like '''EncodeDate''' function, except this function returns ''TRUE'' or ''FALSE'' depending on the success of the operation. If operation was successful, function will return ''TRUE'' and the generated date value will be written in the '''Date''' variable. |
|- | |- | ||
| function '''TryEncodeTime'''(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean; | | function '''TryEncodeTime'''(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean; | ||
− | | Behaves exactly like '''EncodeTime''' function, except this function returns the TRUE or FALSE depending on the success of the operation. If operation was successful, function will return TRUE and the generated time value will be written in the ''' | + | | Behaves exactly like '''EncodeTime''' function, except this function returns ''TRUE'' or ''FALSE'' depending on the success of the operation. If operation was successful, function will return ''TRUE'' and the generated time value will be written in the '''Time''' variable. |
+ | |- | ||
+ | | function '''TryEncodeDateTime'''(Year, Month, Day, Hour, Minute, Second, MilliSecond: Word; out ADateTime: TDateTime): Boolean; | ||
+ | | Behaves exactly like '''EncodeDateTime''' function, except this function returns ''TRUE'' or ''FALSE'' depending on the success of the operation. If operation was successful, function will return ''TRUE'' and the generated date-time value will be written in the '''ADateTime''' variable.<br/>''Added in v6.2.0.5 Beta.'' | ||
|- | |- | ||
| procedure '''DecodeDate'''(const DateTime: TDateTime; var Year, Month, Day: Word); | | procedure '''DecodeDate'''(const DateTime: TDateTime; var Year, Month, Day: Word); | ||
Line 364: | Line 481: | ||
| Extracts '''Hour''', '''Min''', '''Sec''' and '''MSec''' components from a given '''DateTime''' value. | | Extracts '''Hour''', '''Min''', '''Sec''' and '''MSec''' components from a given '''DateTime''' value. | ||
|- | |- | ||
− | | | + | | procedure '''DecodeDateTime'''(const DateTime: TDateTime; out Year, Month, Day, Hour, Minute, Second, MilliSecond: Word); |
− | | | + | | Similar to '''DecodeDate''' and '''DecodeTime''' but extracts both date and time components at once.<br/>''Added in v6.2.0.5 Beta.'' |
+ | |- | ||
+ | | function '''ComposeDateTime'''(const Date, Time: TDateTime): TDateTime; | ||
+ | | Combine date and time components into a single date-time value.<br/>''Added in v6.2.0.5 Beta.'' | ||
|- | |- | ||
| function '''DateTimeToUnix'''(D: TDateTime): Int64; | | function '''DateTimeToUnix'''(D: TDateTime): Int64; | ||
Line 373: | Line 493: | ||
| Converts a Unix timestamp to a value of '''TDateTime''' type. | | Converts a Unix timestamp to a value of '''TDateTime''' type. | ||
|- | |- | ||
− | | function '''FormatDateTime'''(const | + | | function '''FormatDateTime'''(const Format: String; DateTime: TDateTime): String; |
− | | | + | | Convert date and time value to a string using [[ReNamer:Date and Time format|Date and Time formatting]] specified in the '''Format''' parameter. |
+ | |- | ||
+ | | function '''ScanDateTime'''(const Pattern, Subject: String): TDateTime; | ||
+ | | Convert '''Subject''' string to a date and time value by parsing it according to the [[ReNamer:Date and Time format|Date and Time formatting]] specified in the '''Pattern''' parameter.<br/>''Added in v7.1.0.3 Beta.'' | ||
+ | |- | ||
+ | | function '''TryScanDateTime'''(const Pattern, Subject: String; out DateTime: TDateTime): Boolean; | ||
+ | | Behaves exactly like '''ScanDateTime''' function, except it suppresses errors and returns either ''TRUE'' or ''FALSE'' depending on the success of the operation.<br/>''Added in v7.1.0.3 Beta.'' | ||
|- | |- | ||
| function '''IncYear'''(const AValue: TDateTime; const ANumberOfYears: Integer): TDateTime; | | function '''IncYear'''(const AValue: TDateTime; const ANumberOfYears: Integer): TDateTime; | ||
Line 399: | Line 525: | ||
| function '''IncMilliSecond'''(const AValue: TDateTime; const ANumberOfMilliSeconds: Int64): TDateTime; | | function '''IncMilliSecond'''(const AValue: TDateTime; const ANumberOfMilliSeconds: Int64): TDateTime; | ||
| Increments a TDateTime variable by a number of milliseconds (plus or minus). | | Increments a TDateTime variable by a number of milliseconds (plus or minus). | ||
+ | |- | ||
+ | | function '''SecondSpan'''(const ANow, AThen: TDateTime): Double; | ||
+ | | Calculate the approximate number of seconds between two date-time values.<br/>''Added in v6.2.0.5 Beta.'' | ||
+ | |- | ||
+ | | function '''DayOfWeek'''(const DateTime: TDateTime): Word; | ||
+ | | Returns the day number of the week. Returned values: 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday.<br/>''Before v6.1 this function used to return 1=Sunday to 7=Saturday.'' | ||
+ | |- | ||
+ | | function '''DayOfMonth'''(const DateTime: TDateTime): Word; | ||
+ | | Returns the day number of the month.<br/>''Added in v6.1.'' | ||
+ | |- | ||
+ | | function '''DayOfYear'''(const DateTime: TDateTime): Word; | ||
+ | | Returns the day number of the year.<br/>''Added in v6.1.'' | ||
+ | |- | ||
+ | | function '''WeekOfMonth'''(const DateTime: TDateTime): Word; | ||
+ | | Returns the week number of the month.<br/>''Added in v6.1.'' | ||
+ | |- | ||
+ | | function '''WeekOfYear'''(const DateTime: TDateTime): Word; | ||
+ | | Returns the week number of the year.<br/>''Added in v6.1.'' | ||
|} | |} | ||
+ | |||
+ | {{Top}} | ||
== File Management == | == File Management == | ||
Line 409: | Line 555: | ||
|- | |- | ||
| function '''WideFileSize'''(const FileName: WideString): Int64; | | function '''WideFileSize'''(const FileName: WideString): Int64; | ||
− | | Returns the size of the file. | + | | Returns the size of the file in bytes. If file does not exist "-1" is returned. The return value is of type ''Int64'' which can store the maximum file size of 9,223,372,036,854,775,807 bytes. |
|- | |- | ||
| function '''WideFileExists'''(const FileName: WideString): Boolean; | | function '''WideFileExists'''(const FileName: WideString): Boolean; | ||
Line 417: | Line 563: | ||
| Check whether specified directory exists. Returns TRUE if directory exists, otherwise FALSE. | | Check whether specified directory exists. Returns TRUE if directory exists, otherwise FALSE. | ||
|- | |- | ||
− | | function '''WideForceDirectories'''(Dir: WideString): Boolean; | + | | function '''WideForceDirectories'''(const Dir: WideString): Boolean; |
| Makes sure that that all directories in the path exist. If they don't, function will try to create them, recursively. Returns TRUE if all folders exist or have been successfully created. | | Makes sure that that all directories in the path exist. If they don't, function will try to create them, recursively. Returns TRUE if all folders exist or have been successfully created. | ||
|- | |- | ||
| function '''WideCreateDir'''(const Dir: WideString): Boolean; | | function '''WideCreateDir'''(const Dir: WideString): Boolean; | ||
| Create specified directory (non-recursive). Returns TRUE on success, otherwise FALSE. | | Create specified directory (non-recursive). Returns TRUE on success, otherwise FALSE. | ||
+ | |- | ||
+ | | function '''WideRemoveDir'''(const Dir: WideString): Boolean; | ||
+ | | Remove a directory, if it is empty. Returns TRUE on success, otherwise FALSE. | ||
+ | |||
+ | ''Added in v6.4.0.1 Beta.'' | ||
|- | |- | ||
| function '''WideDeleteFile'''(const FileName: WideString): Boolean; | | function '''WideDeleteFile'''(const FileName: WideString): Boolean; | ||
| Delete physical file from the disk. Returns TRUE on success, otherwise FALSE. | | Delete physical file from the disk. Returns TRUE on success, otherwise FALSE. | ||
+ | |- | ||
+ | | function '''WideDeleteToRecycleBin'''(const FileName: WideString): Boolean; | ||
+ | | Delete file or folder by placing it into the Recycle Bin. Returns TRUE on success, otherwise FALSE. | ||
+ | |||
+ | '''Note:''' You must provide a full path to delete the file to the Recycle Bin (a quirk of Windows API). | ||
+ | |||
+ | ''Added in v6.4.0.1 Beta.'' | ||
|- | |- | ||
| function '''WideRenameFile'''(const OldName, NewName: WideString): Boolean; | | function '''WideRenameFile'''(const OldName, NewName: WideString): Boolean; | ||
| Rename file from '''OldName''' to '''NewName'''. Returns TRUE on success, otherwise FALSE. | | Rename file from '''OldName''' to '''NewName'''. Returns TRUE on success, otherwise FALSE. | ||
|- | |- | ||
− | | function '''WideCopyFile'''(FromFile, ToFile: WideString; FailIfExists: Boolean): Boolean; | + | | function '''WideCopyFile'''(const FromFile, ToFile: WideString; FailIfExists: Boolean): Boolean; |
| Rename file from '''FromFile''' to '''ToFile'''. If '''FailIfExists''' flag is TRUE, file will not be copied when destination file already exists, otherwise, destination file will be overwritten. Returns TRUE on success, otherwise FALSE. | | Rename file from '''FromFile''' to '''ToFile'''. If '''FailIfExists''' flag is TRUE, file will not be copied when destination file already exists, otherwise, destination file will be overwritten. Returns TRUE on success, otherwise FALSE. | ||
|- | |- | ||
Line 435: | Line 593: | ||
| Search through the directories passed in '''DirList''' for a file named '''Name'''. DirList is a list of path names delimited by semicolons. If file matching Name is located, function returns a string specifying a path name for that file. If no matching file exists, function returns an empty string. | | Search through the directories passed in '''DirList''' for a file named '''Name'''. DirList is a list of path names delimited by semicolons. If file matching Name is located, function returns a string specifying a path name for that file. If no matching file exists, function returns an empty string. | ||
|- | |- | ||
− | + | | procedure '''WideScanDirForFiles'''(const Dir: WideString; var Files: TWideStringArray; const Recursive, IncludeHidden, IncludeSystem: Boolean; const Mask: WideString); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | | procedure '''WideScanDirForFiles'''(Dir: WideString; var Files: | ||
| You can get a list of the files inside a folder. | | You can get a list of the files inside a folder. | ||
*'''Dir''': The folder you want to scan. | *'''Dir''': The folder you want to scan. | ||
Line 448: | Line 600: | ||
*'''IncludeHidden''': Do you want to list the hidden files? | *'''IncludeHidden''': Do you want to list the hidden files? | ||
*'''IncludeSystem''': Do you want to list the system files? | *'''IncludeSystem''': Do you want to list the system files? | ||
− | *'''Mask''': | + | *'''Mask''': List only the files which match a [[ReNamer:Masks|wildcard mask]], or specify an empty string to list all files. |
|- | |- | ||
− | | procedure '''WideScanDirForFolders'''(Dir: WideString; var Folders: | + | | procedure '''WideScanDirForFolders'''(const Dir: WideString; var Folders: TWideStringArray; const Recursive, IncludeHidden, IncludeSystem: Boolean); |
| You can get a list of the folders inside other folder. | | You can get a list of the folders inside other folder. | ||
*'''Dir''': The folder you want to scan. | *'''Dir''': The folder you want to scan. | ||
Line 458: | Line 610: | ||
*'''IncludeSystem''': Do you want to list the system folders? | *'''IncludeSystem''': Do you want to list the system folders? | ||
|} | |} | ||
+ | |||
+ | {{Top}} | ||
== File Name Utilities == | == File Name Utilities == | ||
Line 467: | Line 621: | ||
|- | |- | ||
| function '''WideExtractFilePath'''(const FileName: WideString): WideString; | | function '''WideExtractFilePath'''(const FileName: WideString): WideString; | ||
− | | Returns the | + | | Returns the drive and directory portion from "FileName", including the trailing path delimiter, e.g. "C:\Folder\". |
|- | |- | ||
| function '''WideExtractFileDir'''(const FileName: WideString): WideString; | | function '''WideExtractFileDir'''(const FileName: WideString): WideString; | ||
− | | Returns the | + | | Returns the drive and directory portion from "FileName", excluding the trailing path delimiter, e.g. "C:\Folder". |
|- | |- | ||
| function '''WideExtractFileDrive'''(const FileName: WideString): WideString; | | function '''WideExtractFileDrive'''(const FileName: WideString): WideString; | ||
− | | Returns the drive letter | + | | Returns the drive letter, e.g. "C:". |
|- | |- | ||
| function '''WideExtractFileName'''(const FileName: WideString): WideString; | | function '''WideExtractFileName'''(const FileName: WideString): WideString; | ||
− | | Returns the filename with extension | + | | Returns the filename with extension, e.g. "FileName.txt". |
|- | |- | ||
| function '''WideExtractBaseName'''(const FileName: WideString): WideString; | | function '''WideExtractBaseName'''(const FileName: WideString): WideString; | ||
− | | Returns | + | | Returns the base name of the file, i.e. file name without extension and path components. |
+ | |||
+ | {| | ||
+ | ! Input | ||
+ | ! Output | ||
+ | |- | ||
+ | | Document.txt | ||
+ | | Document | ||
+ | |- | ||
+ | | C:\Folder\Document.txt | ||
+ | | Document | ||
+ | |} | ||
+ | |||
|- | |- | ||
| function '''WideExtractFileExt'''(const FileName: WideString): WideString; | | function '''WideExtractFileExt'''(const FileName: WideString): WideString; | ||
− | | Returns the file's extension with the dot | + | | Returns the file's extension with the dot, e.g. ".txt". |
|- | |- | ||
| function '''WideChangeFileExt'''(const FileName, Extension: WideString): WideString; | | function '''WideChangeFileExt'''(const FileName, Extension: WideString): WideString; | ||
− | | Replaces the original extension, and returns the new filename with extension | + | | Replaces the original extension, and returns the new filename with extension, e.g. "FineName.txt" -> "FineName.pdf". |
|- | |- | ||
| function '''WideStripExtension'''(const FileName: WideString): WideString; | | function '''WideStripExtension'''(const FileName: WideString): WideString; | ||
− | | Strips off the extension from the filename. | + | | Strips off the extension from the filename, maintaining the path component unaffected. |
+ | |||
+ | {| | ||
+ | ! Input | ||
+ | ! Output | ||
+ | |- | ||
+ | | Document.txt | ||
+ | | Document | ||
+ | |- | ||
+ | | C:\Folder\Document.txt | ||
+ | | C:\Folder\Document | ||
+ | |} | ||
+ | |||
|- | |- | ||
| function '''WideExpandFileName'''(const FileName: WideString): WideString; | | function '''WideExpandFileName'''(const FileName: WideString): WideString; | ||
Line 512: | Line 690: | ||
|- | |- | ||
| function '''WideIncludeTrailingPathDelimiter'''(const S: WideString): WideString; | | function '''WideIncludeTrailingPathDelimiter'''(const S: WideString): WideString; | ||
− | | | + | | With this function you can ensure that a path for a folder '''contains''' the path delimiter ("\") at the end of the path. |
|- | |- | ||
| function '''WideExcludeTrailingPathDelimiter'''(const S: WideString): WideString; | | function '''WideExcludeTrailingPathDelimiter'''(const S: WideString): WideString; | ||
− | | | + | | With this function you can ensure that a path for a file does '''not contain''' the path delimiter ("\") at the end of the path. |
|- | |- | ||
− | | function '''WideSameFileName'''(const | + | | function '''WideSameFileName'''(const FileName1, FileName2: WideString): Boolean; |
− | | Compares the filenames ''' | + | | Compares the filenames '''FileName1''' and '''FileName2''', and returns ''TRUE'' if they are considered to be same. |
+ | |||
+ | Note that filenames on Windows platform are case insensitive for comparison purposes, but case preserving when creating new files. | ||
+ | |||
+ | ''Added in v6.7.0.4 Beta.'' | ||
|- | |- | ||
− | | function ''' | + | | function '''WideMatchesMask'''(const FileName, Mask: WideString): Boolean; |
− | | | + | | Check if '''FileName''' matches a [[ReNamer:Masks|wildcard mask]] '''Mask'''. Return ''TRUE'' if matches, otherwise ''FALSE''. |
− | < | + | |
− | + | For example, a mask <code>*.txt</code> matches files with a <code>.txt</code> extension. | |
− | + | ||
− | + | ''Added in v6.7.0.4 Beta.'' | |
− | + | |- | |
− | + | | function '''WideMatchesMaskList'''(const FileName, MaskList: WideString): Boolean; | |
− | + | | Check if '''FileName''' matches any of the [[ReNamer:Masks|wildcard masks]] listed in '''MaskList'''. The list of masks is separated by semicolons (";"). Return ''TRUE'' if matches, otherwise ''FALSE''. | |
− | </ | + | |
+ | For example, a mask list <code>*.txt;*.doc</code> matches files with a <code>.txt</code> or <code>.doc</code> extension. | ||
+ | |||
+ | ''Added in v6.7.0.4 Beta.'' | ||
|} | |} | ||
+ | |||
+ | {{Top}} | ||
== File Read/Write == | == File Read/Write == | ||
Line 541: | Line 728: | ||
| function '''FileReadFragment'''(const FileName: WideString; Start, Length: Integer): String; | | function '''FileReadFragment'''(const FileName: WideString; Start, Length: Integer): String; | ||
| Starting at position '''Start''', read '''Length''' number of characters of the file '''FileName''' and return them as a string. '''Start''' is 0-based, so in order to start the fragment at the beginning of the file, set this parameter to 0 (zero). | | Starting at position '''Start''', read '''Length''' number of characters of the file '''FileName''' and return them as a string. '''Start''' is 0-based, so in order to start the fragment at the beginning of the file, set this parameter to 0 (zero). | ||
+ | |- | ||
+ | | function '''FileReadLines'''(const FileName: WideString): TAnsiStringArray; | ||
+ | | Read all lines from a file '''FileName'''.<br/>''Added in v5.74.4 Beta.'' | ||
|- | |- | ||
| function '''FileReadLine'''(const FileName: WideString; LineNum: Integer): String; | | function '''FileReadLine'''(const FileName: WideString; LineNum: Integer): String; | ||
Line 556: | Line 746: | ||
| procedure '''FileAppendContent'''(const FileName: WideString; const Content: String); | | procedure '''FileAppendContent'''(const FileName: WideString; const Content: String); | ||
| Append '''Content''' to the end of the file. If target file does not exist, it will be created. | | Append '''Content''' to the end of the file. If target file does not exist, it will be created. | ||
+ | |- | ||
+ | | function '''FileReadText'''(const FileName: WideString): WideString; | ||
+ | | Read text from a file, performing automatic text encoding handling.<br/>''Added in v6.6.0.6 Beta.'' | ||
+ | |- | ||
+ | | function '''FileReadTextLines'''(const FileName: WideString): TWideStringArray; | ||
+ | | Read lines of text from a file, performing automatic text encoding handling.<br/>''Added in v6.7.0.1 Beta.'' | ||
|} | |} | ||
+ | |||
+ | Note: Automatic text encoding handling is based on [https://en.wikipedia.org/wiki/Byte_order_mark byte order mark] (BOM) and supports UTF-8, UTF-16BE and UTF-16LE. If no BOM found then text is interpreted as ANSI encoding. | ||
+ | |||
+ | {{Top}} | ||
== File Time == | == File Time == | ||
Line 577: | Line 777: | ||
| Sets last modified time for the specified file. | | Sets last modified time for the specified file. | ||
|} | |} | ||
+ | |||
+ | {{Top}} | ||
+ | |||
+ | == Meta Tags Extraction == | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Function | ||
+ | ! Remarks | ||
+ | |- | ||
+ | | function '''CalculateMetaTag'''(const FilePath: WideString; const MetaTagName: String): WideString; | ||
+ | | Extracts and returns the value of a meta tag specified by '''MetaTagName''' from the file specified by the complete absolute path '''FilePath'''.<br/>''Return type changed from String to WideString in v5.74.4 Beta.'' | ||
+ | |- | ||
+ | | function '''CalculateMetaTagFormat'''(const FilePath: WideString; const MetaTagName, DateTimeFormat: String): WideString; | ||
+ | | Same as '''CalculateMetaTag''' except an additional parameter '''DateTimeFormat''' is provided to specify custom Date/Time format to be used instead of the application's default setting.<br/>''Added in v5.74.4 Beta.'' | ||
+ | |} | ||
+ | |||
+ | For example, to extract '''EXIF_Date''' tag from an image and set it to the filename using the default date/time formatting: | ||
+ | <syntaxhighlight lang="pascal"> | ||
+ | begin | ||
+ | FileName := CalculateMetaTag(FilePath, 'EXIF_Date'); | ||
+ | end. | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | The full list of meta tags can be found in [[ReNamer:Meta Tags|Meta Tags]] article. For help with date/time formatting refer to [[ReNamer:Date and Time format|Date and Time format]]. | ||
+ | |||
+ | {{Top}} | ||
+ | |||
+ | == Regular Expressions == | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Function | ||
+ | ! Remarks | ||
+ | |- | ||
+ | | function '''IsMatchingRegEx'''(const Input, Pattern: WideString; const CaseSensitive: Boolean): Boolean; | ||
+ | | Check for a match against a RegEx pattern.<br/>''Added in v5.74.4 Beta.'' | ||
+ | |- | ||
+ | | function '''ReplaceRegEx'''(const Input, Find, Replace: WideString; const CaseSensitive, UseSubstitution: Boolean): WideString; | ||
+ | | Find and replace all RegEx pattern matches. Works like the [[ReNamer:Rules:RegEx|Regular Expressions rule]]. | ||
+ | |||
+ | Parameters: | ||
+ | * '''Input''' - The original subject text. | ||
+ | * '''Find''' - The search pattern. | ||
+ | * '''Replace''' - The replacement pattern. | ||
+ | * '''CaseSensitive''' - Search for the pattern in case-sensitive mode. | ||
+ | * '''UseSubstitution''' - Substitute [[ReNamer:Regular Expressions#Backreferences|backreferences]] in the replacement pattern. | ||
+ | |- | ||
+ | | function '''FindRegEx'''(const Input, Find: WideString; const CaseSensitive: Boolean; out Positions: TIntegerArray; out Matches: TWideStringArray): Integer; | ||
+ | | Find matches and positions of a RegEx pattern. Returns the number of matches. | ||
+ | |||
+ | Parameters: | ||
+ | * '''Input''' - The original subject text. | ||
+ | * '''Find''' - The search pattern. | ||
+ | * '''CaseSensitive''' - Search for the pattern in case-sensitive mode. | ||
+ | * '''Positions''' - Receives a list of positions where the matches have been found. | ||
+ | * '''Matches''' - Receives a list of matches. | ||
+ | |||
+ | ''Added in v7.3.0.4 Beta.'' | ||
+ | |- | ||
+ | | function '''MatchesRegEx'''(const Input, Find: WideString; const CaseSensitive: Boolean): TWideStringArray; | ||
+ | | Returns a list of RegEx matches as an array. Function returns an array of full matches, which matched the entire expression, not the sub-patterns. | ||
+ | |- | ||
+ | | function '''SubMatchesRegEx'''(const Input, Find: WideString; const CaseSensitive: Boolean): TWideStringArray; | ||
+ | | This function is very similar to '''MatchesRegEx''', but instead of returning full matches it will return an array of sub-expression matches for the '''first''' full match. | ||
+ | |||
+ | In this way, it can easily be combined with '''MatchesRegEx''' function, to allow users to find all global matches, and then parse those matches through '''SubMatchesRegEx''' function to find individual sub-expression matches of each global match. | ||
+ | |} | ||
+ | |||
+ | Example input and matches for '''MatchesRegEx''' and '''SubMatchesRegEx''' functions: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Input | ||
+ | ! Find | ||
+ | ! MatchesRegEx matches | ||
+ | ! SubMatchesRegEx matches | ||
+ | |- | ||
+ | | A1_B2_C3 | ||
+ | | [A-Z]\d | ||
+ | | | ||
+ | * A1 | ||
+ | * B2 | ||
+ | * C3 | ||
+ | | ''(empty)'' | ||
+ | |- | ||
+ | | A1_B2_C3 | ||
+ | | ([A-Z])(\d) | ||
+ | | | ||
+ | * A1 | ||
+ | * B2 | ||
+ | * C3 | ||
+ | | | ||
+ | * A | ||
+ | * 1 | ||
+ | |} | ||
+ | |||
+ | {{Top}} | ||
== Process Execution == | == Process Execution == | ||
Line 587: | Line 885: | ||
| function '''ShellOpenFile'''(const FileName: WideString): Boolean; | | function '''ShellOpenFile'''(const FileName: WideString): Boolean; | ||
| Run (open) a file specified by '''FileName'''. Works like "Start > Run" command. Parameter does not have to be an executable file, it can by any file or protocol with assigned handler. For example, you can open a Word document or a web page, and associated application will be launched: | | Run (open) a file specified by '''FileName'''. Works like "Start > Run" command. Parameter does not have to be an executable file, it can by any file or protocol with assigned handler. For example, you can open a Word document or a web page, and associated application will be launched: | ||
− | < | + | * <tt><nowiki>ShellOpenFile('http://www.den4b.com/');</nowiki></tt> |
− | + | * <tt><nowiki>ShellOpenFile('C:\Document.doc');</nowiki></tt> | |
− | * | + | |
− | </ | + | '''Beware:''' This function will evaluate the command for the appropriate way of execution which may sometimes lead to unexpected results. For example when executing ''ShellOpenFile('notepad')'' it could actually run a ''Windows Notepad'' application normally located in "''C:\Windows\notepad.exe''", or some other "''notepad.exe''" file located on the search path (''%PATH%''), or even open "''notepad''" folder located in the current working directory. |
|- | |- | ||
| function '''ExecuteProgram'''(const Command: String; WaitForProgram: Boolean): Cardinal; | | function '''ExecuteProgram'''(const Command: String; WaitForProgram: Boolean): Cardinal; | ||
− | | Execute a command | + | | Execute a command specified by '''Command''' parameter. Parameter '''WaitForProgram''' allows you to specify whether the code needs to wait until the command (launched program) has finished executing. |
+ | |- | ||
+ | | function '''ExecuteProgramShow'''(const Command: String; WaitForProgram: Boolean; ShowWindowFlag: Word): Cardinal; | ||
+ | | Execute a command specified by '''Command''' parameter. '''WaitForProgram''' parameter allows you to specify whether the code needs to wait until the command (launched program) has finished executing. '''ShowWindowFlag''' parameter controls how the window is to be shown. | ||
+ | |||
+ | Commonly used values for '''ShowWindowFlag''' parameter: | ||
+ | * 0 = Hide the window. | ||
+ | * 1 = Activate and display the window. | ||
+ | * 2 = Activate the window and display it minimized. | ||
+ | * 3 = Activate the window and display it maximized. | ||
+ | * 4 = Display the window, but do not activate it. | ||
+ | * 7 = Display the window minimized, but do not activate it. | ||
+ | * More information: [http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx ShowWindow Windows API function]. | ||
+ | |||
+ | ''Added in v5.75.3 Beta.'' | ||
|- | |- | ||
| function '''ExecConsoleApp'''(const CommandLine: String; out Output: String): Cardinal; | | function '''ExecConsoleApp'''(const CommandLine: String; out Output: String): Cardinal; | ||
− | | Execute a command line specified by | + | | Execute a command line specified by '''CommandLine''' parameter and capture its standard output in the '''Output''' variable. This function should be used only for console style applications. Returns the exit code. |
+ | |||
+ | Console application output uses OEM-defined character set by default, unless application itself changes its output code page. '''OemToAnsi''' and '''OemToWide''' functions can be used to convert OEM output. | ||
+ | |||
+ | Prior to ''v6.6.0.2 Beta'', OEM to ANSI conversion was automatically applied to the console output. As of ''v6.6.0.2 Beta'', the console output is returned "as is" without any modifications, so to prevent corruption of binary or non-OEM encoded output. | ||
|} | |} | ||
+ | |||
+ | {{Top}} | ||
== Dialogs == | == Dialogs == | ||
Line 631: | Line 949: | ||
|} | |} | ||
− | == | + | {{Top}} |
+ | |||
+ | == Application == | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Function | ||
+ | ! Remarks | ||
+ | |- | ||
+ | | function '''GetApplicationPath''': WideString; | ||
+ | | Return full path to the application, for example: "C:\Program Files\ReNamer\ReNamer.exe". | ||
+ | |- | ||
+ | | function '''GetApplicationParams''': TWideStringArray; | ||
+ | | Return an array of command line parameters which were supplied to the application at launch. | ||
+ | |- | ||
+ | | function '''GetCurrentFileIndex''': Integer; | ||
+ | | Get index of the current file. Index ranges from '''1''' to '''GetTotalNumberOfFiles'''. | ||
+ | |- | ||
+ | | function '''GetTotalNumberOfFiles''': Integer; | ||
+ | | Get total number of files in the application. | ||
+ | |- | ||
+ | | function '''GetCurrentMarkedFileIndex''': Integer; | ||
+ | | Get index of the current file, counting only ''marked'' files. Index ranges from '''1''' to '''GetTotalNumberOfMarkedFiles'''. | ||
+ | |- | ||
+ | | function '''GetTotalNumberOfMarkedFiles''': Integer; | ||
+ | | Get total number of ''marked'' files in the application. | ||
+ | |- | ||
+ | | function '''GetAllFiles''': TWideStringArray; | ||
+ | | Get file paths of all available files. ''Added in v5.74.2 Beta.'' | ||
+ | |- | ||
+ | | function '''GetMarkedFiles''': TWideStringArray; | ||
+ | | Get file paths of all marked files. ''Added in v5.74.2 Beta.'' | ||
+ | |} | ||
+ | |||
+ | {{Top}} | ||
+ | |||
+ | == Global Variables == | ||
+ | |||
+ | Global variables allow for efficient storage and exchange of information between scripts. | ||
+ | |||
+ | Variables do not get cleared automatically, so they exist until cleared manually or until the application terminates. If you wish to clear variables at each Preview, a good mechanism to do that is via the [[ReNamer:Pascal_Script:Initialization_of_variables|script initialization]]. | ||
+ | |||
+ | ''Added in v7.4.0.2 Beta.'' | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 637: | Line 997: | ||
! Function | ! Function | ||
! Remarks | ! Remarks | ||
+ | |- | ||
+ | | procedure '''SetGlobalVar'''(const Name: String; Value: Variant); | ||
+ | | Set a global variable. | ||
+ | |- | ||
+ | | function '''GetGlobalVar'''(const Name: String): Variant; | ||
+ | | Get a global variable. If variable does not exist, the function returns an ''Unassigned'' value. | ||
+ | |- | ||
+ | | function '''GetGlobalVarDef'''(const Name: String; Default: Variant): Variant; | ||
+ | | Get a global variable. If variable does not exist, the function returns the ''Default'' value. | ||
+ | |- | ||
+ | | function '''HasGlobalVar'''(const Name: String): Boolean; | ||
+ | | Check if a global variable exists. | ||
+ | |- | ||
+ | | function '''GetGlobalVarCount''': Integer; | ||
+ | | Retrieve the total number of global variables. | ||
+ | |- | ||
+ | | function '''GetGlobalVarNames''': TAnsiStringArray; | ||
+ | | Retrieve names of all global variables. | ||
+ | |- | ||
+ | | procedure '''ClearGlobalVar'''(const Name: String); | ||
+ | | Clear a global variable. | ||
+ | |- | ||
+ | | procedure '''ClearGlobalVars'''; | ||
+ | | Clear all global variables. | ||
+ | |} | ||
+ | |||
+ | {{Top}} | ||
+ | |||
+ | == System == | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Function | ||
+ | ! Remarks | ||
+ | |- | ||
+ | | function '''WideGetCurrentDir''': WideString; | ||
+ | | Returns the current working directory. | ||
+ | |- | ||
+ | | function '''WideSetCurrentDir'''(const Dir: WideString): Boolean; | ||
+ | | Sets the current working directory to the directory specified by parameter '''Dir'''. | ||
+ | |- | ||
+ | | function '''WideGetTempPath''': WideString; | ||
+ | | Returns system defined temporary directory. If returned value is empty it means that temporary folder could not be determined. | ||
+ | |- | ||
+ | | function '''WideGetEnvironmentVar'''(const VarName: WideString): WideString; | ||
+ | | Returns an environment variable by its name. For example: | ||
+ | <syntaxhighlight lang="pascal"> | ||
+ | var | ||
+ | UserName, ComputerName: WideString; | ||
+ | begin | ||
+ | UserName := WideGetEnvironmentVar('USERNAME'); | ||
+ | ComputerName := WideGetEnvironmentVar('COMPUTERNAME'); | ||
+ | end. | ||
+ | </syntaxhighlight> | ||
+ | |} | ||
+ | |||
+ | {{Top}} | ||
+ | |||
+ | == Miscellaneous == | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Function | ||
+ | ! Remarks | ||
+ | |- | ||
+ | | procedure '''Error'''(const Message: String); | ||
+ | | Abruptly terminate the script with an error message.<br/>''Added in v7.2.0.7 Beta.'' | ||
|- | |- | ||
| procedure '''Sleep'''(Milliseconds: Cardinal); | | procedure '''Sleep'''(Milliseconds: Cardinal); | ||
Line 645: | Line 1,072: | ||
|- | |- | ||
| procedure '''Randomize'''; | | procedure '''Randomize'''; | ||
− | | Prepares the random number generator. Should only be called once per application cycle | + | | Prepares the random number generator. |
+ | '''Note:''' Should only be called once per application cycle, at the start of the process! | ||
|- | |- | ||
| function '''RandomRange'''(const AFrom, ATo: Integer): Integer; | | function '''RandomRange'''(const AFrom, ATo: Integer): Integer; | ||
− | | Return a random integer number within the specified '''AFrom'''..''' | + | | Return a random integer number within the specified range from '''AFrom''' (inclusive) to '''ATo''' (non-inclusive). |
+ | |- | ||
+ | | function '''RandomFloat''': Extended; | ||
+ | | Return a random floating point value between 0.0 (including) and 1.0 (excluding).<br/>''Added in v6.2.0.8 Beta.'' | ||
+ | |- | ||
+ | | function '''RandomBoolean''': Boolean; | ||
+ | | Return a random boolean value, either ''True'' or ''False''.<br/>''Added in v6.2.0.8 Beta.'' | ||
+ | |- | ||
+ | | function '''RandomString'''(Len: Integer; const Chars: String): String; | ||
+ | | Generate a random string of length '''Len''' using characters selected at random from a string '''Chars'''.<br/>''Added in v6.7.0.4 Beta.'' | ||
+ | |- | ||
+ | | function '''MinInt'''(const A, B: Integer): Integer; | ||
+ | | Return the smallest of two values '''A''' and '''B''' of ''Integer'' type.<br/>''Added in v6.2.0.8 Beta.'' | ||
+ | |- | ||
+ | | function '''MinInt64'''(const A, B: Int64): Int64; | ||
+ | | Return the smallest of two values '''A''' and '''B''' of ''Int64'' type.<br/>''Added in v6.2.0.8 Beta.'' | ||
+ | |- | ||
+ | | function '''MinFloat'''(const A, B: Extended): Extended; | ||
+ | | Return the smallest of two values '''A''' and '''B''' of ''Extended'' type.<br/>''Added in v6.2.0.8 Beta.'' | ||
+ | |- | ||
+ | | function '''MaxInt'''(const A, B: Integer): Integer; | ||
+ | | Return the largest of two values '''A''' and '''B''' of ''Integer'' type.<br/>''Added in v6.2.0.8 Beta.'' | ||
+ | |- | ||
+ | | function '''MaxInt64'''(const A, B: Int64): Int64; | ||
+ | | Return the largest of two values '''A''' and '''B''' of ''Int64'' type.<br/>''Added in v6.2.0.8 Beta.'' | ||
+ | |- | ||
+ | | function '''MaxFloat'''(const A, B: Extended): Extended; | ||
+ | | Return the largest of two values '''A''' and '''B''' of ''Extended'' type.<br/>''Added in v6.2.0.8 Beta.'' | ||
|- | |- | ||
| function '''GetClipboardText''': WideString; | | function '''GetClipboardText''': WideString; | ||
Line 660: | Line 1,115: | ||
|- | |- | ||
| function '''Base64Decode'''(const S: String): String; | | function '''Base64Decode'''(const S: String): String; | ||
− | | Decode [http://en.wikipedia.org/wiki/Base64 Base64] string; | + | | Decode [http://en.wikipedia.org/wiki/Base64 Base64] encoded string. |
+ | |- | ||
+ | | function '''URLDecode'''(const Str: String; UsePlusAsSpace: Boolean): WideString; | ||
+ | | Decode URL encoded string. All occurrences of ''%XX'' hex format are decoded, then entire string is decoded from UTF8. | ||
+ | |||
+ | Optionally, plus signs ("+") can be interpreted as white space by enabling '''UsePlusAsSpace''' parameter, for compatibility with some encoders such as in [http://php.net/manual/en/function.urlencode.php PHP]. | ||
+ | |||
+ | ''Added in v5.74.4 Beta. UsePlusAsSpace parameter added in v6.7.0.1 Beta.'' | ||
+ | |- | ||
+ | | function '''URLEncode'''(const Str: WideString; UsePlusAsSpace: Boolean): String; | ||
+ | | Encode string using URL encoding. Input string is encoded with UTF8, then all characters except digits and Latin letters are encoded in ''%XX'' hex format. | ||
+ | |||
+ | Optionally, white spaces can be encoded as plus signs ("+") by enabling '''UsePlusAsSpace''' parameter, for compatibility with some decoders such as in [http://php.net/manual/en/function.urldecode.php PHP]. | ||
+ | |||
+ | ''Added in v5.74.4 Beta.'' | ||
|- | |- | ||
| function '''GetTickCount''': Cardinal; | | function '''GetTickCount''': Cardinal; | ||
Line 668: | Line 1,137: | ||
| Pass a variable reference to determine the number of bytes used to represent the variable. Pass a type identifier to determine the number of bytes used to represent instances of that type. | | Pass a variable reference to determine the number of bytes used to represent the variable. Pass a type identifier to determine the number of bytes used to represent instances of that type. | ||
|} | |} | ||
+ | |||
+ | {{Top}} | ||
[[Category:ReNamer]] | [[Category:ReNamer]] | ||
[[Category:Pascal Script]] | [[Category:Pascal Script]] |
Latest revision as of 16:53, 31 July 2024
ReNamer has many functions to manipulate the entities related to file names and do some more complex tasks for individual files. These entities may be derived from the existing filename, path, system date, meta tags from the file, strings entered by the user, etc. This functionality is available for use via the PascalScript rule.
The difference between a "function" and a "procedure" is that while a function executes an algorithm and returns a value, a procedure just executes an algorithm without returning anything.
A common "Wide" prefix in function names indicates that the function deals with WideString type rather than AnsiString or String type. For example, ShowMessage and WideShowMessage procedures. See the String Types for more information.
Basic String Handling
Routine | Remarks |
---|---|
procedure Insert(Source: String; var S: String; Index: Integer); | Inserts the string S into string Source at position Index. |
procedure Delete(var S: String; Index, Count: Integer); | Deletes Count characters from the string S, starting from position Index. |
function Copy(S: String; Index, Count: Integer): String; | Copies Count characters from string S, starting at position Index, and returns them as a new string. |
function Pos(Substr: String; S: String): Integer; | Returns the position of a string Substr in another string S. |
Note: Indexes of characters in strings are 1 based, so first character in string S would be S[1].
Length Management
Routine | Remarks |
---|---|
procedure SetLength(var S: Array; NewLength: Integer); | Sets the length of array variable S to NewLength. |
procedure SetLength(var S: String; NewLength: Integer); | Sets the length of string variable S to NewLength. |
procedure SetLength(var S: WideString; NewLength: Integer); | Sets the length of widestring S to NewLength. |
function Length(const S: Array): Integer; | Returns the length of array S (number of elements). |
function Length(const S: String): Integer; | Returns the length of string S (number of characters). |
function Length(const S: WideString): Integer; | Returns the length of WideString S (number of characters). |
Wide String Handling
Routine | Remarks |
---|---|
procedure WideInsert(const Substr: WideString; var Dest: WideString; Index: Integer); | Inserts Substr in Dest at position Index. |
procedure WideDelete(var S: WideString; Index, Count: Integer); | Deletes Count characters from S, starting from the Index position. |
procedure WideDeleteRight(var S: WideString; Index, Count: Integer); | Delete Count characters from S, starting from the Index position from the end and counting towards the start.
Added in v6.0.0.9 Alpha. |
procedure WideSetLength(var S: WideString; NewLength: Integer); | Change the length of string S to a new length specified by NewLength. If new length is smaller than original, the string is truncated. If new length is greater than original, the string will be expanded but additional characters will not be initialized and can be anything. |
function WideLength(const S: WideString): Integer; | Returns the length of WideString S. |
function WideCopy(const S: WideString; Index, Count: Integer): WideString; | Returns Count characters from S, starting at position Index. |
function WideCopyRight(const S: WideString; Index, Count: Integer): WideString; | Returns Count characters from S, starting at position Index from the end and counting towards the start.
Added in v6.0.0.9 Alpha. |
function WidePos(const SubStr, S: WideString): Integer; | Find and occurrence of SubStr in S. Returns the position of first occurrence, or 0 if nothing was found. |
function WidePosEx(const SubStr, S: WideString; Offset: Cardinal): Integer; | Find and occurrence of SubStr in S but start searching from position specified by Offset. Returns the position of first occurrence, or 0 if nothing was found. |
function WideUpperCase(const S: WideString): WideString; | Returns the ALLCAPS version of the WideString S |
function WideLowerCase(const S: WideString): WideString; | Returns the lowercase version of the WideString S |
function WideCompareStr(const S1, S2: WideString): Integer; | Compares two WideStrings S1 and S2, case-sensitive, and returns an integer based on the result. The return value is less than 0 if S1 is less than S2, 0 if S1 equals S2, or greater than 0 if S1 is greater than S2. |
function WideCompareText(const S1, S2: WideString): Integer; | Compares two WideStrings S1 and S2, case-insensitive, and returns an integer based on the result. The return value is less than 0 if S1 is less than S2, 0 if S1 equals S2, or greater than 0 if S1 is greater than S2. |
function WideSameText(const S1, S2: WideString): Boolean; | Compares two WideStrings S1 and S2, case-insensitive. Returns TRUE if both are identical, otherwise returns FALSE. |
function WideTextPos(const SubStr, S: WideString): Integer; | Behaves like WidePos function, except text if processed in case-insensitive manner. |
function WideTextPosEx(const SubStr, S: WideString; Offset: Cardinal): Integer; | Behaves like WidePosEx function, except text if processed in case-insensitive manner.
Added in v6.6.0.1 Beta. |
function WideTrim(const S: WideString): WideString; | Removes leading and trailing spaces and control characters from the given string S. |
function WideTrimChars(const S, CharsToTrim: WideString): WideString; | Remove characters that occur in CharsToTrim from the beginning and the end of S.
Added in v6.0.0.9 Alpha. |
function WideTrimCharsLeft(const S, CharsToTrim: WideString): WideString; | Remove characters that occur in CharsToTrim from the beginning of S.
Added in v6.0.0.9 Alpha. |
function WideTrimCharsRight(const S, CharsToTrim: WideString): WideString; | Remove characters that occur in CharsToTrim from the end of S.
Added in v6.0.0.9 Alpha. |
function WideReverseString(const S: WideString): WideString; | Return a reversed version of string S, i.e. reverse the order of characters.
Added in v6.7.0.4 Beta. |
function WideRepeatString(const S: WideString; Count: Integer): WideString; | Repeat a string a number of times. Added in v6.9.0.3 Beta. |
function WideReplaceStr(const S, OldPattern, NewPattern: WideString): WideString; | Return a result of a case-sensitive replacement of all occurrences of OldPattern with NewPattern in a string S. |
function WideReplaceText(const S, OldPattern, NewPattern: WideString): WideString; | Return a result of a case-insensitive replacement of all occurrences of OldPattern with NewPattern in a string S. |
function WideSplitString(const Input, Delimiter: WideString): TWideStringArray; |
Splits the Input wherever Delimiter occurs and returns an array that contains the split parts.
|
function WideJoinStrings(const Strings: TWideStringArray; const Delimiter: WideString): WideString; | Joins all individual items from Strings into a single WideString, with Delimiter inserted between the joined items. |
function WideCaseSentence(const S: WideString): WideString; | Returns a Sentence case version of parameter S.
Only the first alphabetic character is capitalized. All other alphabetic characters are converted to lowercase. Added in v6.0.0.3 Alpha. |
function WideCaseCapitalize(const S: WideString): WideString; |
Returns the Title case version of parameter S. First letter of every word is capitalized. All other alphabetic characters are converted to lowercase. |
function WideCaseInvert(const S: WideString): WideString; | Inverts case of all characters in S and returns it. |
Wide String Array Handling
Function | Remarks |
---|---|
procedure WideAppendStringArray(var Strings: TWideStringArray; const NewString: WideString); | Add a WideString to the end of a WideString array. Added in v7.5.0.3 Beta. |
function WideCopyStringArray(const Strings: TWideStringArray; Index, Count: Integer): TWideStringArray; | Copy a portion of a WideString array by taking Count elements starting from Index position. Added in v7.5.0.3 Beta. |
function WideConcatStringArrays(const A, B: TWideStringArray): TWideStringArray; | Concatenate two WideString arrays. Added in v7.5.0.3 Beta. |
Wide Character Handling
Function | Remarks |
---|---|
function IsWideCharUpper(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is in upper case. |
function IsWideCharLower(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is in lower case. |
function IsWideCharDigit(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a digit (numeric character 0-9). |
function IsWideCharSpace(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a white-space character, such as: space, form-feed, newline, carriage-return, tab and vertical-tab (characters classified as C1_SPACE). |
function IsWideCharPunct(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a punctuation mark (characters classified as C1_PUNCT). |
function IsWideCharCntrl(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a control character (characters classified as C1_CNTRL). |
function IsWideCharBlank(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a blank, such as: space and tab (characters classified as C1_BLANK). |
function IsWideCharXDigit(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a hexadecimal digit (0-9 or A-F). |
function IsWideCharAlpha(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a alphanumeric character (a-z or A-Z). |
function IsWideCharAlphaNumeric(WC: WideChar): Boolean; | Checks character WC and returns TRUE if it is a alphanumeric character or a numeric character (a-z, A-Z or 0-9). |
function IsWideWordBoundaryLeft(const Subject: WideString; CharPosition: Integer): Boolean; | Check if a character at the specified position is on a word boundary to the left.
Conditions that qualify as word boundaries to the left of character:
Added in v6.6.0.1 Beta. |
function IsWideWordBoundaryRight(const Subject: WideString; CharPosition: Integer): Boolean; | Check if a character at the specified position is on a word boundary to the right.
Conditions that qualify as word boundaries to the right of character:
Added in v6.6.0.1 Beta. |
function WideCharUpper(const WC: WideChar): WideChar; | Returns an upper case version of the input character. In case of non-alphabetic character, it returns the same character. |
function WideCharLower(const WC: WideChar): WideChar; | Returns a lower case version of the input character. In case of non-alphabetic character, it returns the same character. |
function WideChr(Code: Word): WideChar; | Create a character from a code point. Added in v6.9.0.3 Beta. |
Note: Character classifications, such as C1_UPPER, C1_LOWER, C1_DIGIT, C1_SPACE, C1_PUNCT, C1_CNTRL, C1_BLANK, C1_XDIGIT, C1_ALPHA - are part of Unicode definitions. More information regarding classification can be found on the internet. For example: http://www.fileformat.info/info/unicode/.
Unicode Conversion
Function | Remarks |
---|---|
function WideToAnsi(const WS: WideString): String; | Convert WideString type to AnsiString type. In v7.0 and later, this conversion is performed automatically on assignment. |
function AnsiToWide(const S: String): WideString; | Convert AnsiString type to WideString type. In v7.0 and later, this conversion is performed automatically on assignment. |
function UTF8Encode(const WS: WideString): String; | Convert WideString type to UTF-8 encoded string. |
function UTF8Decode(const S: String): WideString; | Convert UTF-8 encoded string to WideString type. |
function WinCPToUTF8(const S: String): String; | Convert a string encoded with active system code page to a UTF-8 encoded string. Added in v7.4.0.3 Beta. |
function UTF8ToWinCP(const S: String): String; | Convert a UTF-8 encoded string to a string encoded with active system code page. Added in v7.4.0.3 Beta. |
See String types for additional information on the default encoding and conversion procedures.
Console Output Conversion
OEM-defined character set is commonly used in the output of console applications.
Function | Remarks |
---|---|
function OemToAnsi(const S: String): String; | Convert OEM string into an ANSI string. Added in v6.6.0.2 Beta. |
function OemToWide(const S: String): WideString; | Convert OEM string into a WideString. Added in v6.6.0.2 Beta. |
function AnsiToOem(const S: String): String; | Convert ANSI string into an OEM string. Added in v6.6.0.2 Beta. |
function WideToOem(const S: WideString): String; | Convert WideString into an OEM string. Added in v6.6.0.2 Beta. |
Basic Conversion
Function | Remarks |
---|---|
function BoolToStr(B: Boolean): String; | Convert boolean variable into a string. Returns "True" or "False" string value. |
function IntToStr(Value: Integer): String; | Converts an integer to a string. The following assumptions are correct:
Note: Be cautious of supplying Int64 type as a parameter as it will be type casted to Integer, which significantly reduces the range of possible values (refer to Types for more information). You can use FormatFloat function to convert Int64 values to a string without a loss of range. |
function Int64ToStr(Value: Int64): String; | Same as IntToStr but takes in Int64 typed parameter. |
function StrToInt(const S: String): Integer; | Converts a string to an integer. The following equalities are correct:
Warning: An error will occur if the parameter to this function cannot be converted to an integer! |
function StrToInt64(const S: String): Int64; | Same as StrToInt but returns Int64 typed result. |
function StrToIntDef(const S: String; const Default: Integer): Integer; | Behaves like StrToInt function, but instead of producing an error on incorrect input function allows the Default value to be specified, which will be returned if the input cannot be converted to an integer. |
function StrToInt64Def(const S: String; Default: Int64): Int64; | Same as StrToIntDef but operates with Int64 type. |
function TryStrToInt(const S: String; out Value: Integer): Boolean; | Converts a string to an integer, but does not throw an error when invalid string is supplied, unlike StrToInt. Returns False if conversion operation has failed. |
function FloatToStr(Value: Extended): string; | Converts supplied floating point value to its string representation, using default system format. |
function StrToFloat(const S: string): Extended; | Converts supplied string to a floating point value. Warning: An error will occur if the parameter to this function cannot be converted to a floating point value! |
function StrToFloatDef(const S: string; const Default: Extended): Extended; | Behaves like StrToFloat function, but instead of producing an error on incorrect input function allows the Default value to be specified, which will be returned if the input cannot be converted to a floating point value. |
function FormatFloat(const Format: string; Value: Extended): string; | Converts supplied floating point value to its string representation, using user specific Format. Check floating point format specifiers below for more information. |
function DateToStr(D: TDateTime): String; | Converts a date to a string, using system format for the short date, for example: dd/mm/yyyy. |
function StrToDate(const S: String): TDateTime; | Converts a date string to a proper TDateTime value, using system format for the short date, for example: dd/mm/yyyy. |
function IntToHex(Value: Integer; Digits: Integer): String; | Converts an integer to its hexadecimal representation. Here are samples:
|
function HexToInt(const HexNum: String): Integer; | Converts a hexadecimal value to its decimal representation. Warning: An error will occur if the parameter to this function cannot be converted to an integer! |
function HexToIntDef(const HexNum: String; Default: Integer): Integer; | Behaves like HexToInt function, but instead of producing an error on incorrect input function allows the Default value to be specified, which will be returned if the input cannot be converted to an integer. |
function IntToRoman(Value: Integer): String; | Convert a decimal number to Roman numerals. Added in v7.3.0.4 Beta. |
function RomanToInt(const S: String): Integer; | Convert Roman numerals to a decimal number. Added in v7.3.0.4 Beta. |
function RomanToIntDef(const S: String; Default: Integer): Integer; | Convert Roman numerals to a decimal number. Returns the Default value in the conversion fails. Added in v7.3.0.4 Beta. |
function TryRomanToInt(const S: String; out Value: Integer): Boolean; | Try to convert Roman numerals to a decimal number. Does not throw an error on failure, instead it returns False. Added in v7.3.0.4 Beta. |
function Ord(X: Char): Byte; | Return an ordinal value (byte representation) of a character. |
function Chr(X: Byte): Char; | Return a character by its ordinal value (byte representation). |
Floating point format specifiers
Specifier | Represents |
---|---|
0 (zero) | Digit placeholder. If the value being formatted has a digit in the position where the "0" appears in the format string, then that digit is copied to the output string. Otherwise, a "0" is stored in that position in the output string. |
# (hash) | Digit placeholder. If the value being formatted has a digit in the position where the "#" appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string. |
. (dot) | Decimal point. The first "." character in the format string determines the location of the decimal separator in the formatted value, any additional "." characters are ignored. |
, (comma) | Thousand separator. If the format string contains one or more "," characters, the output will have thousand separators inserted between each group of three digits to the left of the decimal point. The placement and number of "," characters in the format string does not affect the output. |
Date and Time
Function | Remarks |
---|---|
function Date: TDateTime; | Returns the current system date. |
function Time: TDateTime; | Returns the current system time. |
function Now: TDateTime; | Returns the current system date and time. |
function EncodeDate(Year, Month, Day: Word): TDateTime; | Generates date value for the specified Year, Month, Day. Parameters must be within a valid date range: Year = 0..9999, Month = 1..12, Day = 1..31 (depending on month/year). An error will be raised if parameters are invalid. |
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime; | Generates time value for the specified Hour, Min, Sec, MSec. Parameters must be within a valid time range: Hour = 0..23, Min = 0..59, Sec = 0..59, MSec = 0..999. An error will be raised if parameters are invalid. |
function EncodeDateTime(Year, Month, Day, Hour, Minute, Second, MilliSecond: Word): TDateTime; | Generates date-time value for the specified components of date and time. Similar to EncodeDate and EncodeTime. Added in v6.2.0.5 Beta. |
function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean; | Behaves exactly like EncodeDate function, except this function returns TRUE or FALSE depending on the success of the operation. If operation was successful, function will return TRUE and the generated date value will be written in the Date variable. |
function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean; | Behaves exactly like EncodeTime function, except this function returns TRUE or FALSE depending on the success of the operation. If operation was successful, function will return TRUE and the generated time value will be written in the Time variable. |
function TryEncodeDateTime(Year, Month, Day, Hour, Minute, Second, MilliSecond: Word; out ADateTime: TDateTime): Boolean; | Behaves exactly like EncodeDateTime function, except this function returns TRUE or FALSE depending on the success of the operation. If operation was successful, function will return TRUE and the generated date-time value will be written in the ADateTime variable. Added in v6.2.0.5 Beta. |
procedure DecodeDate(const DateTime: TDateTime; var Year, Month, Day: Word); | Extracts Year, Month and Day components from a given DateTime value. |
procedure DecodeTime(const DateTime: TDateTime; var Hour, Min, Sec, MSec: Word); | Extracts Hour, Min, Sec and MSec components from a given DateTime value. |
procedure DecodeDateTime(const DateTime: TDateTime; out Year, Month, Day, Hour, Minute, Second, MilliSecond: Word); | Similar to DecodeDate and DecodeTime but extracts both date and time components at once. Added in v6.2.0.5 Beta. |
function ComposeDateTime(const Date, Time: TDateTime): TDateTime; | Combine date and time components into a single date-time value. Added in v6.2.0.5 Beta. |
function DateTimeToUnix(D: TDateTime): Int64; | Converts D value of type TDateTime to a Unix timestamp. |
function UnixToDateTime(U: Int64): TDateTime; | Converts a Unix timestamp to a value of TDateTime type. |
function FormatDateTime(const Format: String; DateTime: TDateTime): String; | Convert date and time value to a string using Date and Time formatting specified in the Format parameter. |
function ScanDateTime(const Pattern, Subject: String): TDateTime; | Convert Subject string to a date and time value by parsing it according to the Date and Time formatting specified in the Pattern parameter. Added in v7.1.0.3 Beta. |
function TryScanDateTime(const Pattern, Subject: String; out DateTime: TDateTime): Boolean; | Behaves exactly like ScanDateTime function, except it suppresses errors and returns either TRUE or FALSE depending on the success of the operation. Added in v7.1.0.3 Beta. |
function IncYear(const AValue: TDateTime; const ANumberOfYears: Integer): TDateTime; | Increments a TDateTime variable by a number of years (plus or minus). |
function IncMonth(const AValue: TDateTime; ANumberOfMonths: Integer): TDateTime; | Increments a TDateTime variable by a number of months (plus or minus). |
function IncWeek(const AValue: TDateTime; const ANumberOfWeeks: Integer): TDateTime; | Increments a TDateTime variable by a number of weeks (plus or minus). |
function IncDay(const AValue: TDateTime; const ANumberOfDays: Integer): TDateTime; | Increments a TDateTime variable by a number of days (plus or minus). |
function IncHour(const AValue: TDateTime; const ANumberOfHours: Int64): TDateTime; | Increments a TDateTime variable by a number of hours (plus or minus). |
function IncMinute(const AValue: TDateTime; const ANumberOfMinutes: Int64): TDateTime; | Increments a TDateTime variable by a number of minutes (plus or minus). |
function IncSecond(const AValue: TDateTime; const ANumberOfSeconds: Int64): TDateTime; | Increments a TDateTime variable by a number of seconds (plus or minus). |
function IncMilliSecond(const AValue: TDateTime; const ANumberOfMilliSeconds: Int64): TDateTime; | Increments a TDateTime variable by a number of milliseconds (plus or minus). |
function SecondSpan(const ANow, AThen: TDateTime): Double; | Calculate the approximate number of seconds between two date-time values. Added in v6.2.0.5 Beta. |
function DayOfWeek(const DateTime: TDateTime): Word; | Returns the day number of the week. Returned values: 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday. Before v6.1 this function used to return 1=Sunday to 7=Saturday. |
function DayOfMonth(const DateTime: TDateTime): Word; | Returns the day number of the month. Added in v6.1. |
function DayOfYear(const DateTime: TDateTime): Word; | Returns the day number of the year. Added in v6.1. |
function WeekOfMonth(const DateTime: TDateTime): Word; | Returns the week number of the month. Added in v6.1. |
function WeekOfYear(const DateTime: TDateTime): Word; | Returns the week number of the year. Added in v6.1. |
File Management
Function | Remarks |
---|---|
function WideFileSize(const FileName: WideString): Int64; | Returns the size of the file in bytes. If file does not exist "-1" is returned. The return value is of type Int64 which can store the maximum file size of 9,223,372,036,854,775,807 bytes. |
function WideFileExists(const FileName: WideString): Boolean; | Check whether specified file exists. Returns TRUE if file exists, otherwise FALSE. |
function WideDirectoryExists(const Directory: WideString): Boolean; | Check whether specified directory exists. Returns TRUE if directory exists, otherwise FALSE. |
function WideForceDirectories(const Dir: WideString): Boolean; | Makes sure that that all directories in the path exist. If they don't, function will try to create them, recursively. Returns TRUE if all folders exist or have been successfully created. |
function WideCreateDir(const Dir: WideString): Boolean; | Create specified directory (non-recursive). Returns TRUE on success, otherwise FALSE. |
function WideRemoveDir(const Dir: WideString): Boolean; | Remove a directory, if it is empty. Returns TRUE on success, otherwise FALSE.
Added in v6.4.0.1 Beta. |
function WideDeleteFile(const FileName: WideString): Boolean; | Delete physical file from the disk. Returns TRUE on success, otherwise FALSE. |
function WideDeleteToRecycleBin(const FileName: WideString): Boolean; | Delete file or folder by placing it into the Recycle Bin. Returns TRUE on success, otherwise FALSE.
Note: You must provide a full path to delete the file to the Recycle Bin (a quirk of Windows API). Added in v6.4.0.1 Beta. |
function WideRenameFile(const OldName, NewName: WideString): Boolean; | Rename file from OldName to NewName. Returns TRUE on success, otherwise FALSE. |
function WideCopyFile(const FromFile, ToFile: WideString; FailIfExists: Boolean): Boolean; | Rename file from FromFile to ToFile. If FailIfExists flag is TRUE, file will not be copied when destination file already exists, otherwise, destination file will be overwritten. Returns TRUE on success, otherwise FALSE. |
function WideFileSearch(const Name, DirList: WideString): WideString; | Search through the directories passed in DirList for a file named Name. DirList is a list of path names delimited by semicolons. If file matching Name is located, function returns a string specifying a path name for that file. If no matching file exists, function returns an empty string. |
procedure WideScanDirForFiles(const Dir: WideString; var Files: TWideStringArray; const Recursive, IncludeHidden, IncludeSystem: Boolean; const Mask: WideString); | You can get a list of the files inside a folder.
|
procedure WideScanDirForFolders(const Dir: WideString; var Folders: TWideStringArray; const Recursive, IncludeHidden, IncludeSystem: Boolean); | You can get a list of the folders inside other folder.
|
File Name Utilities
Function | Remarks | ||||||
---|---|---|---|---|---|---|---|
function WideExtractFilePath(const FileName: WideString): WideString; | Returns the drive and directory portion from "FileName", including the trailing path delimiter, e.g. "C:\Folder\". | ||||||
function WideExtractFileDir(const FileName: WideString): WideString; | Returns the drive and directory portion from "FileName", excluding the trailing path delimiter, e.g. "C:\Folder". | ||||||
function WideExtractFileDrive(const FileName: WideString): WideString; | Returns the drive letter, e.g. "C:". | ||||||
function WideExtractFileName(const FileName: WideString): WideString; | Returns the filename with extension, e.g. "FileName.txt". | ||||||
function WideExtractBaseName(const FileName: WideString): WideString; | Returns the base name of the file, i.e. file name without extension and path components.
| ||||||
function WideExtractFileExt(const FileName: WideString): WideString; | Returns the file's extension with the dot, e.g. ".txt". | ||||||
function WideChangeFileExt(const FileName, Extension: WideString): WideString; | Replaces the original extension, and returns the new filename with extension, e.g. "FineName.txt" -> "FineName.pdf". | ||||||
function WideStripExtension(const FileName: WideString): WideString; | Strips off the extension from the filename, maintaining the path component unaffected.
| ||||||
function WideExpandFileName(const FileName: WideString): WideString; | Converts the relative file name into a fully qualified path. This function does not verify that the resulting path refers to an existing file. | ||||||
function WideExtractRelativePath(const BaseName, DestName: WideString): WideString; | Creates a relative path to go from BaseName to DestName. For example:
| ||||||
function WideExtractShortPathName(const FileName: WideString): WideString; | It converts a path into it's representation in DOS format. | ||||||
function WideIncludeTrailingPathDelimiter(const S: WideString): WideString; | With this function you can ensure that a path for a folder contains the path delimiter ("\") at the end of the path. | ||||||
function WideExcludeTrailingPathDelimiter(const S: WideString): WideString; | With this function you can ensure that a path for a file does not contain the path delimiter ("\") at the end of the path. | ||||||
function WideSameFileName(const FileName1, FileName2: WideString): Boolean; | Compares the filenames FileName1 and FileName2, and returns TRUE if they are considered to be same.
Note that filenames on Windows platform are case insensitive for comparison purposes, but case preserving when creating new files. Added in v6.7.0.4 Beta. | ||||||
function WideMatchesMask(const FileName, Mask: WideString): Boolean; | Check if FileName matches a wildcard mask Mask. Return TRUE if matches, otherwise FALSE.
For example, a mask Added in v6.7.0.4 Beta. | ||||||
function WideMatchesMaskList(const FileName, MaskList: WideString): Boolean; | Check if FileName matches any of the wildcard masks listed in MaskList. The list of masks is separated by semicolons (";"). Return TRUE if matches, otherwise FALSE.
For example, a mask list Added in v6.7.0.4 Beta. |
File Read/Write
Function | Remarks |
---|---|
function FileReadFragment(const FileName: WideString; Start, Length: Integer): String; | Starting at position Start, read Length number of characters of the file FileName and return them as a string. Start is 0-based, so in order to start the fragment at the beginning of the file, set this parameter to 0 (zero). |
function FileReadLines(const FileName: WideString): TAnsiStringArray; | Read all lines from a file FileName. Added in v5.74.4 Beta. |
function FileReadLine(const FileName: WideString; LineNum: Integer): String; | Read a line from a file FileName specified by a line index LineNum. LineNum is 1 based, so to get the first line set this parameter to 1 (one). Note: This function is extremely inefficient and provided only for convenience! |
function FileCountLines(const FileName: WideString): Integer; | Count number of lines in the file. Note: This function is extremely inefficient and provided only for convenience! |
function FileReadContent(const FileName: WideString): String; | Return the entire content of the file as a String. |
procedure FileWriteContent(const FileName: WideString; const Content: String); | Write Content to the file. If target file already exists, it will be overwritten. |
procedure FileAppendContent(const FileName: WideString; const Content: String); | Append Content to the end of the file. If target file does not exist, it will be created. |
function FileReadText(const FileName: WideString): WideString; | Read text from a file, performing automatic text encoding handling. Added in v6.6.0.6 Beta. |
function FileReadTextLines(const FileName: WideString): TWideStringArray; | Read lines of text from a file, performing automatic text encoding handling. Added in v6.7.0.1 Beta. |
Note: Automatic text encoding handling is based on byte order mark (BOM) and supports UTF-8, UTF-16BE and UTF-16LE. If no BOM found then text is interpreted as ANSI encoding.
File Time
Function | Remarks |
---|---|
function FileTimeModified(const FileName: WideString): TDateTime; | Returns last modified time of the specified file. |
function FileTimeCreated(const FileName: WideString): TDateTime; | Returns creation time of the specified file. |
function SetFileTimeCreated(const FileName: WideString; const DateTime: TDateTime): Boolean; | Sets creation time for the specified file. |
function SetFileTimeModified(const FileName: WideString; const DateTime: TDateTime): Boolean; | Sets last modified time for the specified file. |
Meta Tags Extraction
Function | Remarks |
---|---|
function CalculateMetaTag(const FilePath: WideString; const MetaTagName: String): WideString; | Extracts and returns the value of a meta tag specified by MetaTagName from the file specified by the complete absolute path FilePath. Return type changed from String to WideString in v5.74.4 Beta. |
function CalculateMetaTagFormat(const FilePath: WideString; const MetaTagName, DateTimeFormat: String): WideString; | Same as CalculateMetaTag except an additional parameter DateTimeFormat is provided to specify custom Date/Time format to be used instead of the application's default setting. Added in v5.74.4 Beta. |
For example, to extract EXIF_Date tag from an image and set it to the filename using the default date/time formatting:
begin
FileName := CalculateMetaTag(FilePath, 'EXIF_Date');
end.
The full list of meta tags can be found in Meta Tags article. For help with date/time formatting refer to Date and Time format.
Regular Expressions
Function | Remarks |
---|---|
function IsMatchingRegEx(const Input, Pattern: WideString; const CaseSensitive: Boolean): Boolean; | Check for a match against a RegEx pattern. Added in v5.74.4 Beta. |
function ReplaceRegEx(const Input, Find, Replace: WideString; const CaseSensitive, UseSubstitution: Boolean): WideString; | Find and replace all RegEx pattern matches. Works like the Regular Expressions rule.
Parameters:
|
function FindRegEx(const Input, Find: WideString; const CaseSensitive: Boolean; out Positions: TIntegerArray; out Matches: TWideStringArray): Integer; | Find matches and positions of a RegEx pattern. Returns the number of matches.
Parameters:
Added in v7.3.0.4 Beta. |
function MatchesRegEx(const Input, Find: WideString; const CaseSensitive: Boolean): TWideStringArray; | Returns a list of RegEx matches as an array. Function returns an array of full matches, which matched the entire expression, not the sub-patterns. |
function SubMatchesRegEx(const Input, Find: WideString; const CaseSensitive: Boolean): TWideStringArray; | This function is very similar to MatchesRegEx, but instead of returning full matches it will return an array of sub-expression matches for the first full match.
In this way, it can easily be combined with MatchesRegEx function, to allow users to find all global matches, and then parse those matches through SubMatchesRegEx function to find individual sub-expression matches of each global match. |
Example input and matches for MatchesRegEx and SubMatchesRegEx functions:
Input | Find | MatchesRegEx matches | SubMatchesRegEx matches |
---|---|---|---|
A1_B2_C3 | [A-Z]\d |
|
(empty) |
A1_B2_C3 | ([A-Z])(\d) |
|
|
Process Execution
Function | Remarks |
---|---|
function ShellOpenFile(const FileName: WideString): Boolean; | Run (open) a file specified by FileName. Works like "Start > Run" command. Parameter does not have to be an executable file, it can by any file or protocol with assigned handler. For example, you can open a Word document or a web page, and associated application will be launched:
Beware: This function will evaluate the command for the appropriate way of execution which may sometimes lead to unexpected results. For example when executing ShellOpenFile('notepad') it could actually run a Windows Notepad application normally located in "C:\Windows\notepad.exe", or some other "notepad.exe" file located on the search path (%PATH%), or even open "notepad" folder located in the current working directory. |
function ExecuteProgram(const Command: String; WaitForProgram: Boolean): Cardinal; | Execute a command specified by Command parameter. Parameter WaitForProgram allows you to specify whether the code needs to wait until the command (launched program) has finished executing. |
function ExecuteProgramShow(const Command: String; WaitForProgram: Boolean; ShowWindowFlag: Word): Cardinal; | Execute a command specified by Command parameter. WaitForProgram parameter allows you to specify whether the code needs to wait until the command (launched program) has finished executing. ShowWindowFlag parameter controls how the window is to be shown.
Commonly used values for ShowWindowFlag parameter:
Added in v5.75.3 Beta. |
function ExecConsoleApp(const CommandLine: String; out Output: String): Cardinal; | Execute a command line specified by CommandLine parameter and capture its standard output in the Output variable. This function should be used only for console style applications. Returns the exit code.
Console application output uses OEM-defined character set by default, unless application itself changes its output code page. OemToAnsi and OemToWide functions can be used to convert OEM output. Prior to v6.6.0.2 Beta, OEM to ANSI conversion was automatically applied to the console output. As of v6.6.0.2 Beta, the console output is returned "as is" without any modifications, so to prevent corruption of binary or non-OEM encoded output. |
Dialogs
Function | Remarks |
---|---|
procedure ShowMessage(const Msg: String); | Show a simple dialog with the message specified by Msg parameter. |
procedure WideShowMessage(const Msg: WideString); | Same as ShowMessage function but parameter is Unicode text. |
function DialogYesNo(const Msg: String): Boolean; | Show a simple prompt with the message specified by Msg parameter and two button: Yes and No. Returns TRUE if user clicks Yes button, otherwise FALSE. |
function WideDialogYesNo(const Msg: WideString): Boolean; | Same as DialogYesNo function but parameter is WideString text. |
function InputBox(const ACaption, APrompt, ADefault: String): String; | Displays a simple dialog box with the given ACaption and APrompt message. It asks the user to enter data in a text box on the dialog. A ADefault value is displayed in the text box initially. If the user presses OK, the value from the text box is returned, otherwise ADefault value is returned. |
function InputQuery(const ACaption, APrompt: String; var Value: String): Boolean; | Operates similar to InputBox function. The default value and the value of the text box after the dialog is closed are transferred via the Value parameter. Function returns TRUE is user clicked OK, otherwise returns FALSE. |
function WideInputBox(const ACaption, APrompt, ADefault: WideString): WideString; | Same as InputBox function but operates on WideString text. |
function WideInputQuery(const ACaption, APrompt: WideString; var Value: WideString): Boolean; | Same as InputQuery function but operates on WideString text. |
Application
Function | Remarks |
---|---|
function GetApplicationPath: WideString; | Return full path to the application, for example: "C:\Program Files\ReNamer\ReNamer.exe". |
function GetApplicationParams: TWideStringArray; | Return an array of command line parameters which were supplied to the application at launch. |
function GetCurrentFileIndex: Integer; | Get index of the current file. Index ranges from 1 to GetTotalNumberOfFiles. |
function GetTotalNumberOfFiles: Integer; | Get total number of files in the application. |
function GetCurrentMarkedFileIndex: Integer; | Get index of the current file, counting only marked files. Index ranges from 1 to GetTotalNumberOfMarkedFiles. |
function GetTotalNumberOfMarkedFiles: Integer; | Get total number of marked files in the application. |
function GetAllFiles: TWideStringArray; | Get file paths of all available files. Added in v5.74.2 Beta. |
function GetMarkedFiles: TWideStringArray; | Get file paths of all marked files. Added in v5.74.2 Beta. |
Global Variables
Global variables allow for efficient storage and exchange of information between scripts.
Variables do not get cleared automatically, so they exist until cleared manually or until the application terminates. If you wish to clear variables at each Preview, a good mechanism to do that is via the script initialization.
Added in v7.4.0.2 Beta.
Function | Remarks |
---|---|
procedure SetGlobalVar(const Name: String; Value: Variant); | Set a global variable. |
function GetGlobalVar(const Name: String): Variant; | Get a global variable. If variable does not exist, the function returns an Unassigned value. |
function GetGlobalVarDef(const Name: String; Default: Variant): Variant; | Get a global variable. If variable does not exist, the function returns the Default value. |
function HasGlobalVar(const Name: String): Boolean; | Check if a global variable exists. |
function GetGlobalVarCount: Integer; | Retrieve the total number of global variables. |
function GetGlobalVarNames: TAnsiStringArray; | Retrieve names of all global variables. |
procedure ClearGlobalVar(const Name: String); | Clear a global variable. |
procedure ClearGlobalVars; | Clear all global variables. |
System
Function | Remarks |
---|---|
function WideGetCurrentDir: WideString; | Returns the current working directory. |
function WideSetCurrentDir(const Dir: WideString): Boolean; | Sets the current working directory to the directory specified by parameter Dir. |
function WideGetTempPath: WideString; | Returns system defined temporary directory. If returned value is empty it means that temporary folder could not be determined. |
function WideGetEnvironmentVar(const VarName: WideString): WideString; | Returns an environment variable by its name. For example:
var
UserName, ComputerName: WideString;
begin
UserName := WideGetEnvironmentVar('USERNAME');
ComputerName := WideGetEnvironmentVar('COMPUTERNAME');
end.
|
Miscellaneous
Function | Remarks |
---|---|
procedure Error(const Message: String); | Abruptly terminate the script with an error message. Added in v7.2.0.7 Beta. |
procedure Sleep(Milliseconds: Cardinal); | Sleep (pause the execution) for specified number of Milliseconds. |
procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: Word); | Perform integer division and fetch the remainder as well, all in one operation. Dividend is the integer into which you are dividing. Divisor is the value by which to divide Dividend. Result returns the result of the integer division. Remainder returns the remainder (the difference between Result * Divisor and Dividend). |
procedure Randomize; | Prepares the random number generator.
Note: Should only be called once per application cycle, at the start of the process! |
function RandomRange(const AFrom, ATo: Integer): Integer; | Return a random integer number within the specified range from AFrom (inclusive) to ATo (non-inclusive). |
function RandomFloat: Extended; | Return a random floating point value between 0.0 (including) and 1.0 (excluding). Added in v6.2.0.8 Beta. |
function RandomBoolean: Boolean; | Return a random boolean value, either True or False. Added in v6.2.0.8 Beta. |
function RandomString(Len: Integer; const Chars: String): String; | Generate a random string of length Len using characters selected at random from a string Chars. Added in v6.7.0.4 Beta. |
function MinInt(const A, B: Integer): Integer; | Return the smallest of two values A and B of Integer type. Added in v6.2.0.8 Beta. |
function MinInt64(const A, B: Int64): Int64; | Return the smallest of two values A and B of Int64 type. Added in v6.2.0.8 Beta. |
function MinFloat(const A, B: Extended): Extended; | Return the smallest of two values A and B of Extended type. Added in v6.2.0.8 Beta. |
function MaxInt(const A, B: Integer): Integer; | Return the largest of two values A and B of Integer type. Added in v6.2.0.8 Beta. |
function MaxInt64(const A, B: Int64): Int64; | Return the largest of two values A and B of Int64 type. Added in v6.2.0.8 Beta. |
function MaxFloat(const A, B: Extended): Extended; | Return the largest of two values A and B of Extended type. Added in v6.2.0.8 Beta. |
function GetClipboardText: WideString; | Get the content of the the clipboard (text only). |
procedure SetClipboardText(const S: WideString); | Set the content of the the clipboard (text only). |
function Base64Encode(const S: String): String; | Encode string S into Base64. Useful for encoding binary data in order to minimize the likelihood of data being modified in transit through different systems, like email or internet. |
function Base64Decode(const S: String): String; | Decode Base64 encoded string. |
function URLDecode(const Str: String; UsePlusAsSpace: Boolean): WideString; | Decode URL encoded string. All occurrences of %XX hex format are decoded, then entire string is decoded from UTF8.
Optionally, plus signs ("+") can be interpreted as white space by enabling UsePlusAsSpace parameter, for compatibility with some encoders such as in PHP. Added in v5.74.4 Beta. UsePlusAsSpace parameter added in v6.7.0.1 Beta. |
function URLEncode(const Str: WideString; UsePlusAsSpace: Boolean): String; | Encode string using URL encoding. Input string is encoded with UTF8, then all characters except digits and Latin letters are encoded in %XX hex format.
Optionally, white spaces can be encoded as plus signs ("+") by enabling UsePlusAsSpace parameter, for compatibility with some decoders such as in PHP. Added in v5.74.4 Beta. |
function GetTickCount: Cardinal; | Retrieves the number of milliseconds that have elapsed since the system was started (up to 49.7 days, then timer resets). The precision of this timer is very limited. |
function SizeOf(X): Integer; | Pass a variable reference to determine the number of bytes used to represent the variable. Pass a type identifier to determine the number of bytes used to represent instances of that type. |