File Control Functionality
In order to enable functionality for organizing files and directories you need to declare a filecontrol item in your
local definitions section of a form, report, or global definitions.
<Filecontrol item> : filecontrol
The following functions and properties are available for filecontrol items:
Function | Description | |
CREATEDIR |
Creates a directory. If an error occurs, this function will return "False" and the system item RESOK will be set
accordingly. Complementary information about the error will be stored in GETLASTRESULT. |
|
Use: |
||
<Filecontrol item>.CREATEDIR (<Directory>) |
||
<Directory> |
Specification (string) of the directory that must be created. Subdirectories may also be included. |
|
Example: MyFileControl.createdir('abc') |
||
FILECOPY |
Copies a file. If an error occurs, this function will return "False" and the system item RESOK will be set accordingly. Complementary information about the error will be stored in GETLASTRESULT. |
|
Use: |
||
<Filecontrol item>.FILECOPY(<Source>, <Destination>) |
||
<Source> |
Expression (string) to point to the file that must be copied from. |
|
<Destination> |
Expression (string) to define the name and location where the source file must be copied to. |
|
Example: MyFileControl.filecopy('C:\boot.ini', 'def\boot.ini') |
||
FILEDELETE |
Deletes a file. If an error occurs, this function will return "False" and the system item RESOK will be set accordingly. Complementary information about the error will be stored in GETLASTRESULT. |
|
Use: |
||
<Filecontrol item>.FILEDELETE(<Filename>) |
||
<Filename> |
Specification (string) to point to the file to be deleted. A path may be included. |
|
Example: MyFileControl.filedelete('def\boot2.ini') |
||
FILEEXISTS |
Tests if a file exists or not. Returns "True" if the file exists, "False" if not. If a relative path is specified then it’s relative to the extract directory. |
|
Use: |
||
<Filecontrol item>.FILEEXISTS(<Filename>) |
||
<Filename> |
Specification (string) to point to the file whose existence is to be checked. A path may be included. |
|
Example: MyFileControl.fileexists('def\boot2.ini') |
||
FILEMOVE |
Moves the file that is specified as <Source> to the <Destination>. Unlike the FILECOPY function, the file that is specified as <Source> will not be retained in its original location. If there is already a file with the same name in <Destination>, it will get overwritten. If an error occurs, this function will return "False" and the system item RESOK will be set accordingly. Complementary information about the error will be stored in GETLASTRESULT. |
|
Use: |
||
<Filecontrol item>.FILEMOVE(<Source>, <Destination>) |
||
<Source> |
Expression (String) that contains the path for the file that must replace the file that is specified as <Destination>. |
|
<Destination> |
Expression that contains the new path for the file. |
|
Example: MyFileControl.filemove('def\boot.ini', 'def\boot2.ini') |
||
FINDDIR |
Returns a String that indicates the first subdirectory or all subdirectories that correspond(s) to the specified <Directory>. |
|
Use: |
||
<Filecontrol item>.FINDDIR (<Directory> [, <All>]) |
||
<Directory> |
Expression (String) to indicate the (sub)directory name to search for. Wild cards may be included. |
|
<All> |
Boolean value to indicate if all matching directories must be returned. If this option is set to false (default), only the first matching directory will be returned. |
|
Examples: s := MyFileControl.finddir ('def\*.*') |
||
FINDFILES |
Returns a String that indicates the details of the first file, or all files, that correspond(s) to the specified <Filename>. Each matching file is described in a separate record. The values, that are all separated with commas (, ), give the following information:
Note: the records for the files are delimited by CR/LF combinations. |
|
Use: |
||
<Filecontrol item>.FINDFILES(<Filename> [, <All> [, <Max>]]) |
||
<Filename> |
Expression (string) to indicate the file name to search for. Wild cards may be included. |
|
<All> |
Optional Boolean value to indicate if all matching file names must be returned. If this option is set to false (default), only the first matching file name is returned. |
|
<Max> |
Optional integer value to limit the searching of all files. Once the set maximum number of files are
found, the function will cease searching. |
|
Examples: s := MyFileControl.findfiles('def\*.*') |
||
GETFILEDATE | Returns a string containing the time-stamps of a file as three date/time values,
comma seperated. time-stamps: <date/time of creation>, (format ddmmccyy hhmmss) <date/time of last access>, (format ddmmccyy hhmmss) <date/time of last modification> (format ddmmccyy hhmmss) |
|
Use: | ||
<Filecontrol item>.GETFILEDATE(<Filename>) | ||
<Filename> | Expression (string) to indicate the file to get the date/time stamps from. | |
Example: s := MyFileControl.getfiledate('D:\Temp\Testfile.txt') |
||
GETFILESIZE | Returns an integer containing the size of a file in bytes. | |
Use: | ||
<Filecontrol item>.GETFILESIZE(<Filename>) | ||
<Filename> | Expression (string) to indicate the file to get the size of. | |
Example: size := MyFileControl.getfilesize('D:\Temp\Testfile.txt') |
||
GIVEFILECONTENT | To read the contents of a file and return it as a string. Reads a file from the disk and returns it as a string. A recordsize has to be specified. The records are then seperated by <CR><LF> sequences in the string at intervals of the recordsize. Lines in the file shorter than the recordsize are automatically filled with spaces to the recordsize. Lines longer than the recordsize are automatically split to multiple records of the specified size. When a recordsize of -1 is specified, then the <CR><LF> sequences are not changed and the file contents is returned as is. |
|
Use: | ||
<Filecontrol item>.GIVEFILECONTENT(<Filename>, <Recordsize>) | ||
<Filename> | Expression (string) to indicate the file to return the contents of. | |
<Recordsize> | The length of the records to return, -1 returns the file contents as is. | |
Example: s := MyFileControl.givefilecontent('D:\Temp\Testfile.txt', 64) |
||
ISFILELOCKED | Checks if a file is locked by another process. Returns boolean True when locked and False otherwise. | |
Use: | ||
<Filecontrol item>.ISFILELOCKED(<Filename>) | ||
<Filename> | Expression (string) to indicate the file to test the locked status of. | |
Example: locked := MyFileControl.isfilelocked('D:\Temp\Testfile.txt') |
||
REMOVEDIR |
Deletes a directory. Deletion will also delete any content of the directory. If an error occurs, this function will return "False" and the system item RESOK will be set accordingly. Complementary information about the error will be stored in GETLASTRESULT. |
|
Use: |
||
<Filecontrol item>.REMOVEDIR (<Directory>) |
||
<Directory> |
Expression (String) to indicate the directory that must be deleted. |
|
RENAMEDIR |
Renames a directory. If an error occurs, this function will return "False" and the system item RESOK will be set accordingly. Complementary information about the error will be stored in GETLASTRESULT. |
|
Use: |
||
<Filecontrol item>.RENAMEDIR (<Old directory>, <New directory>) |
||
<Old directory> |
Expression (String) to indicate the name of the directory that must be renamed. |
|
<New directory> |
Expression (String) to indicate the new directory name that must replace the specified <Old directory>. |
|
Example: MyFileControl.renamedir('abc', 'def') |
||
REPLACESTRING | Replaces all occurrences of the <Original string> in the <Original file> by the
<New string>. When a <New files> is specified the result will be written to the <New
file>, any existing <New file> will be overwritten. When <New file> is
omitted the <Original file> will be overwritten. In case the <New file> specified is
the same as <Original file>, the <Original file> will be overwritten without warning. Returned is True on success of the replace and False on failure. |
|
Use: | ||
<Filecontrol item>.REPLACESTRING(<Original file>, <Original string>, <New string>[, <New file>]) | ||
<Original file> | Expression (String) that specifies the file to replace the strings in | |
<Original string> | The string to be replaced | |
<New string> | The string to replace the <Original string> by | |
<New file> | Expression (String) that specifies an optional new file to write the result to | |
Examples result := MyFileControl.replacestring('D:\Temp\Testfile.txt', '12', 'XYXY') or result := MyFileControl.replacestring('D:\Temp\Testfile.txt', 'abcd', '12', 'D:\Temp\Testfile2.txt') |
||
SHRINKFILETONNRECORDS | Shrinks the number of records in the file specified by <Filename>
and containing more records than specified by <Last record no> of length specified by
<Record size> to the specified <Last record no>. I.e. all records after the <Last record
no> will be deleted from the file. The <Record size> specified should match the actual record size of the file, otherwise results will be unpredictable. On success True is returned, on failure False. |
|
Use: | ||
<Filecontrol item>.SHRINKFILETONNRECORDS(<Filename>, <Record size>, <Last record no>) | ||
<Filename> | Expression (String) specifying the file to shrink | |
<Record size> | The record size to use for shrinking | |
<Last record no> | The number of records to shrink to | |
Example result := MyFileControl.shrinkfiletonnrecords('D:\Temp\Testfile.txt', 64, 312) |
||
SPLITINTORECORDS | Splits long records (lines) in a file specified by <Filename> into shorter
recods of length specified by <Record size>. The result is written into a separate file
specified by <New file>. Returned is True on succes and False on failure. |
|
Use: | ||
<Filecontrol item>.SPLITINTORECORDS(<Filename>, <Record size>, <New file>) | ||
<Filename> | Expression (String) that specifies the file to split the records of | |
<Record size> | The new record size to use for the split | |
<New file> | Expression (String) that specifies the new file to write the result to | |
Example result := MyFileControl.splitintorecords('D:\Temp\Testfile.txt', <32>, 'D:\Temp\Splittedfile.txt') |
||
WRITEFILE |
This writes the <content> to a file with the name <filename>. If <append> is false
the file is overwritten, otherwise the text will be written after the current content. If an error occurs, this function will return "False" and the system item RESOK will be set accordingly. Complementary information about the error will be stored in GETLASTRESULT. |
|
Use: |
||
<Filecontrol item>.WRITEFILE (<filename>, <recordsize>, <content>, <append>) |
||
<filename> |
Expression to indicate the exact name of the file including the filepath to this file. (alpha or string) |
|
<recordsize> |
Expression to indicate the size of the blocks the file has to be written away in. (integer) |
|
<content> |
Content that has to be written in the file. (alpha or string) |
|
<append> |
Expression that indicates if the content has to be overwritten or appended to existing content (boolean) |
|
Example: |