Difference between revisions of "ReNamer:Pascal Script:Functions"
Line 425: | Line 425: | ||
|- | |- | ||
| function '''WideExtractFilePath'''(const FileName: WideString): WideString; | | function '''WideExtractFilePath'''(const FileName: WideString): WideString; | ||
− | | | + | | Returns the entire path of the file <br>(starting from the drive letter) |
|- | |- | ||
| function '''WideExtractFileDir'''(const FileName: WideString): WideString; | | function '''WideExtractFileDir'''(const FileName: WideString): WideString; | ||
− | | | + | | Returns the folder in which the file is located. |
|- | |- | ||
| function '''WideExtractFileDrive'''(const FileName: WideString): WideString; | | function '''WideExtractFileDrive'''(const FileName: WideString): WideString; | ||
− | | | + | | Returns the drive letter<br>???or is it the name of the drive? |
|- | |- | ||
| function '''WideExtractFileName'''(const FileName: WideString): WideString; | | function '''WideExtractFileName'''(const FileName: WideString): WideString; | ||
− | | | + | | Returns the filename with extension. <br>(e.g. "FileName.txt") |
|- | |- | ||
| function '''WideExtractBaseName'''(const FileName: WideString): WideString; | | function '''WideExtractBaseName'''(const FileName: WideString): WideString; | ||
− | | | + | | Retusn only the file' base name (but not the dot or extension). (e.g. "FileName") |
|- | |- | ||
| function '''WideExtractFileExt'''(const FileName: WideString): WideString; | | function '''WideExtractFileExt'''(const FileName: WideString): WideString; | ||
− | | | + | | Returns the file's extension only (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. (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.<br>??? what does it return? |
|- | |- | ||
| function '''WideExpandFileName'''(const FileName: WideString): WideString; | | function '''WideExpandFileName'''(const FileName: WideString): WideString; | ||
− | | | + | | ??? |
|- | |- | ||
| function '''WideExtractRelativePath'''(const BaseName, DestName: WideString): WideString; | | function '''WideExtractRelativePath'''(const BaseName, DestName: WideString): WideString; | ||
| | | | ||
+ | Given two files lacated in two different folders, returns the relative path of '''DestName''' file with respect to the '''BaseName''' file. | ||
+ | |||
+ | e.g. If we input these two filenames: | ||
+ | |||
+ | '''D:\Folder1\FileName1.txt''' (The base file)<br>'''D:\Folder2\Folder22\FileName2.pdf''' (The destination file) | ||
+ | |||
+ | Then the relative path of the destination file is-<br>'''..\Folder2\Folder22\FileName2.pdf''' | ||
+ | |||
|- | |- | ||
| function '''WideExtractShortPathName'''(const FileName: WideString): WideString; | | function '''WideExtractShortPathName'''(const FileName: WideString): WideString; | ||
Line 464: | Line 472: | ||
|- | |- | ||
| function '''WideSameFileName'''(const S1, S2: WideString): Boolean; | | function '''WideSameFileName'''(const S1, S2: WideString): Boolean; | ||
− | | | + | | Compares the filenames '''S1''' and '''S2''', and returns TRUE if they are identical. |
|- | |- | ||
| function '''WideGetEnvironmentVar'''(const VarName: WideString): WideString; | | function '''WideGetEnvironmentVar'''(const VarName: WideString): WideString; | ||
Line 470: | Line 478: | ||
|} | |} | ||
− | <br> | + | <br> |
== File Read/Write Routines == | == File Read/Write Routines == |
Revision as of 15:58, 11 July 2009
Introduction
ReNamer has many procedures and functions to manipulate the entities related to file names. These entities may be derived from the existing filename, path, system date, meta tags from the file, strings entered by the user, etc.
In the following names, the prefix Wide is used to denote that the value is Unicode.
Basic String Handling Routines
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 string. |
function Pos(Substr: String; S: String): Integer; | Returns the position of a string Substr in another string S, |
Length Managing Routines
Routine | |
procedure SetLength(var S: Array; NewLength: Integer); | Sets the length of array variable S as NewLength. |
procedure SetLength(var S: String; NewLength: Integer); | Sets the length of string variable S as NewLength. |
procedure SetLength(var S: WideString; NewLength: Integer); | Sets the length of widestring S as NewLength. |
function Length(const S: Array): Integer; | Returns the length of array S (Returns the number of elements the array S has) |
function Length(const S: String): Integer; | Returns the length of string S |
function Length(const S: WideString): Integer; | Returns the length of WideString S |
Unicode String Handling Routines
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 WideString, starting from the Index position. |
procedure WideSetLength(var S: WideString; NewLength: Integer); |
Sets the length of WideString to Integer. |
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 Widestring S, starting at position Index. |
function WidePos(const SubStr, S: WideString): Integer; | Returns the position of the SubStr in WideString S. |
function WidePosEx(const SubStr, S: WideString; Offset: Cardinal): Integer; | ??? |
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, and returns an integer based on the result. |
function WideCompareText(const S1, S2: WideString): Integer; | Compares two WideStrings S1 and S2, and returns an integer based on the result. ??? what is this integer if S1>S2, S1=S2 ? |
function WideSameText(const S1, S2: WideString): Boolean; | Compares two WideStrings S1 and S2, and returns TRUE if both are identical. |
function WideTextPos(const SubStr, S: WideString): Integer; |
Returns the position of SubStr in S. ??? what happens if the SubStr is not found in S? |
function WideTrim(const S: WideString): WideString; | Trims spaces at both ends (left and right) and returns the trimmed WideString S. Spaces inside S are not affected. ??or from left side only? |
function WideReplaceStr(const S, OldPattern, NewPattern: WideString): WideString; | ??? |
function WideReplaceText(const S, OldPattern, NewPattern: WideString): WideString; | ??? |
function WideSplitString(const Input, Delimiter: WideString): TStringsArray; |
Splits the WideString Input wherever Delimiter occurs, and returns an array that contains the split parts.
|
function WideCaseCapitalize(const S: WideString): WideString; |
Returns the Sentence case version of the WideString S. Only the first alphabetic character is capitalized. All other alphabetic characters are converted to lowercase.
|
function WideCaseInvert(const S: WideString): WideString; | Inverts the case of all characters in the WideString S and returns the WideString. |
Meta Tags Extraction
function CalculateMetaTag(const FilePath: WideString; const MetaTagName String): String; | Extracts and returns the metatag named MetaTagName from the file specified by the complete absolute path FilePath. |
Regular Expressions
Note: The following terms are used:
- Input - The WideString that is input to the function.
- Find - RegEx pattern to be found. (same as Expression field in the RegEx rule)
- Replace - Replacement string (Same as the Replace field in the RegEx rule)
- CaseSensitive - TRUE/FALSE
- UseSubstitution - Determines whether use backreferences in the result.
If it is set to TRUE, the function will change $1-$9 in Replace string with the corresponding parts of Find expression, eg. (.+).
If it is set to False, function will treat $1 as a literal string in the result string. (e.g.. "My_Picture_$1" instead of "My_Picture_365")
Function | |
function ReplaceRegEx(const Input, Find, Replace: WideString;const CaseSensitive, UseSubstitution: Boolean): WideString; |
Find--and-replace function using RegEx. |
function MatchesRegEx(const Input, Find: WideString;const CaseSensitive: Boolean): TStringsArray; | |
function SubMatchesRegEx(const Input, Find: WideString;const CaseSensitive: Boolean): TStringsArray; |
Unicode Character Handling Routines
function IsWideCharUpper(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is in UPPERCASE. |
function IsWideCharLower(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is in lowercase |
function IsWideCharDigit(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is a digit
(numeric character 0-9). |
function IsWideCharSpace(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is a space. |
function IsWideCharPunct(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is a punctuation mark.
@@@ which are these?? |
function IsWideCharCntrl(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is a control character. @@@ which are these?? |
function IsWideCharBlank(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is a blank.
@@@ which are these?? |
function IsWideCharXDigit(WC: WideChar): Boolean; | @@@what is this function? |
function IsWideCharAlpha(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is a alphanumeric character (a-z or A-Z). |
function IsWideCharAlphaNumeric(WC: WideChar): Boolean; | Checks a Unicode character WC and returns TRUE if it is a alphanumeric character or a numeric character (a-z, A-Z or 0-9). |
function WideCharUpper(const WC: WideChar): WideChar; | Returns a UPPERCASE version of the input Unicode character. In case of non-alphabetic character, it returns the same character. @@@correct? |
function WideCharLower(const WC: WideChar): WideChar; | Returns a lowercase version of the input Unicode character. In case of non-alphabetic character, it returns the same character. @@@correct? |
Unicode Conversion Routines
function WideToAnsi(const WS: WideString): String; | Converts a Unicode string to its ANSI version. |
function AnsiToWide(const S: String): WideString; | Converts a ANSI string to its Unicode version. |
function UTF8Encode(const WS: WideString): String; | |
function UTF8Decode(const S: String): WideString; |
Basic Conversion Routines
function IntToStr(Value: Integer): String; | Converts an integer to a string@@@ how exactly? |
function StrToInt(const S: String): Integer; | Converts a string to an integer.
@@@ how exactly? |
function StrToIntDef(const S: String; const Default: Integer): Integer; | |
function DateToStr(D: TDateTime): String; | Converts a date to an string.
@@@ how exactly? What formats are used? How to specify them? |
function StrToDate(const S: String): TDateTime; | Converts a string to an date.
@@@ how exactly? What is the required input format? |
function IntToHex(Value: Integer; Digits: Integer): String; | Converts an integer to its Hexadecimal value.
@@@ how is the hex string formatted? |
function HexToInt(const HexNum: String): Integer; | Converts a Hexadecimal value to its decimal (base 10) value.
@@@ how is the hex string formatted? |
function HexToIntDef(const HexNum: String; Default: Integer): Integer; | |
function Chr(X: Byte): Char; | |
function Ord(X: Char): Byte; |
Date And Time Routines
function Date: TDateTime; | |
function Time: TDateTime; | |
function Now: TDateTime; | |
function EncodeDate(Year, Month, Day: Word): TDateTime; | |
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime; | |
function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean; | |
function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean; | |
procedure DecodeDate(const DateTime: TDateTime; var Year, Month, Day: Word); | |
procedure DecodeTime(const DateTime: TDateTime; var Hour, Min, Sec, MSec: Word); | |
function DayOfWeek(const DateTime: TDateTime): Word; | |
function DateTimeToUnix(D: TDateTime): Int64; | |
function UnixToDateTime(U: Int64): TDateTime; | |
function FormatDateTime(const fmt: String; D: TDateTime): String; | |
function IncYear(const AValue: TDateTime;const ANumberOfYears: Integer): TDateTime; | |
function IncMonth(const AValue: TDateTime;ANumberOfMonths: Integer): TDateTime; | |
function IncWeek(const AValue: TDateTime; | |
const ANumberOfWeeks: Integer): TDateTime; | |
function IncDay(const AValue: TDateTime;const ANumberOfDays: Integer): TDateTime; | |
function IncHour(const AValue: TDateTime;const ANumberOfHours: Int64): TDateTime; | |
function IncMinute(const AValue: TDateTime;const ANumberOfMinutes: Int64): TDateTime; | |
function IncSecond(const AValue: TDateTime;const ANumberOfSeconds: Int64): TDateTime; | |
function IncMilliSecond(const AValue: TDateTime;const ANumberOfMilliSeconds: Int64): TDateTime; |
File Management Routines
function WideFileSize(const FileName: WideString): Int64; | |
function WideFileExists(const FileName: WideString): Boolean; | |
function WideDirectoryExists(const Directory: WideString): Boolean; | |
function WideForceDirectories(Dir: WideString): Boolean; | |
function WideCreateDir(const Dir: WideString): Boolean; | |
function WideDeleteFile(const FileName: WideString): Boolean; | |
function WideRenameFile(const OldName, NewName: WideString): Boolean; | |
function WideFileSearch(const Name, DirList: WideString): WideString; | |
function WideGetCurrentDir: WideString; | |
function WideSetCurrentDir(const Dir: WideString): Boolean; | |
procedure WideScanDirForFiles(Dir: WideString; var Files: TStringsArray;const Recursive, IncludeHidden, IncludeSystem: Boolean; const Mask: WideString); | |
procedure WideScanDirForFolders(Dir: WideString; var Folders: TStringsArray;const Recursive, IncludeHidden, IncludeSystem: Boolean); |
File Name Utilities
function WideExtractFilePath(const FileName: WideString): WideString; | Returns the entire path of the file (starting from the drive letter) |
function WideExtractFileDir(const FileName: WideString): WideString; | Returns the folder in which the file is located. |
function WideExtractFileDrive(const FileName: WideString): WideString; | Returns the drive letter ???or is it the name of the drive? |
function WideExtractFileName(const FileName: WideString): WideString; | Returns the filename with extension. (e.g. "FileName.txt") |
function WideExtractBaseName(const FileName: WideString): WideString; | Retusn only the file' base name (but not the dot or extension). (e.g. "FileName") |
function WideExtractFileExt(const FileName: WideString): WideString; | Returns the file's extension only (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. ??? what does it return? |
function WideExpandFileName(const FileName: WideString): WideString; | ??? |
function WideExtractRelativePath(const BaseName, DestName: WideString): WideString; |
Given two files lacated in two different folders, returns the relative path of DestName file with respect to the BaseName file. e.g. If we input these two filenames: D:\Folder1\FileName1.txt (The base file) Then the relative path of the destination file is- |
function WideExtractShortPathName(const FileName: WideString): WideString; | |
function WideIncludeTrailingPathDelimiter(const S: WideString): WideString; | |
function WideExcludeTrailingPathDelimiter(const S: WideString): WideString; | |
function WideSameFileName(const S1, S2: WideString): Boolean; | Compares the filenames S1 and S2, and returns TRUE if they are identical. |
function WideGetEnvironmentVar(const VarName: WideString): WideString; |
File Read/Write Routines
function FileReadFragment(const FileName: WideString; Start, Length: Integer): String; | |
function FileReadLine(const FileName: WideString; LineNum: Integer): String; | |
function FileCountLines(const FileName: WideString): Integer; | |
function FileReadContent(const FileName: WideString): String; | |
procedure FileWriteContent(const FileName: WideString; const Content: String); | |
procedure FileAppendContent(const FileName: WideString; const Content: String); |
File Properties Routines
function FileTimeModified(const FileName: WideString): TDateTime; | |
function FileTimeCreated(const FileName: WideString): TDateTime; | |
function SetFileTimeCreated(const FileName: WideString;const DateTime: TDateTime): Boolean; | |
function SetFileTimeModified(const FileName: WideString;const DateTime: TDateTime): Boolean; |
Process Execution Routines
function ShellOpenFile(const FileName: WideString): Boolean; | |
function ExecuteProgram(const Command: String; WaitForProgram: Boolean): Cardinal; | |
function ExecConsoleApp(const CommandLine: String; out Output: String): Cardinal; |
Interactive Dialogs
procedure ShowMessage(const Msg: String); | |
procedure WideShowMessage(const Msg: WideString); | |
function DialogYesNo(const Msg: String): Boolean; | |
function WideDialogYesNo(const Msg: WideString): Boolean; | |
function InputBox(const ACaption, APrompt, ADefault: String): String; | |
function InputQuery(const ACaption, APrompt: String; var Value: String): Boolean; | |
function WideInputBox(const ACaption, APrompt, ADefault: WideString): WideString; | |
function WideInputQuery(const ACaption, APrompt: WideString;var Value: WideString): Boolean; |
Other Routines
procedure Randomize(); | |
procedure Sleep(Milliseconds: Cardinal); | Sleeps (waits) for specified miliseconds |
procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: Word); | |
procedure SetClipboardText(const S: WideString); | |
function GetClipboardText: WideString; | |
function RandomRange(const AFrom, ATo: Integer): Integer; | |
function Base64Encode(const S: String): String; | |
function Base64Decode(const S: String): String; | |
function GetTickCount: Cardinal; | |
function SizeOf(X): Integer; |