|
|
|
|
|
- Handling errors
- Operating mode in Windows Vista (and later)
- File opening mode
- Multiple openings of the same file
- Position in the file
- Concatenating several external files
- Compatibility between different versions of WINDEV/WEBDEV
- Locking and unlocking
- Managing UNICODE text files
fOpen (Function) In french: fOuvre Open an external file (ANSI or UNICODE) to manipulate it programmatically. Remarks:
Syntax
Open an external file Hide the details
<Result> = fOpen(<File to manipulate> [, <Opening mode>])
<Result>: Integer or DiskFile variable Corresponds to:- an integer:
- the identifier of the external file. This identifier will be used by all the functions for handling external files.
- -1 if an error occurred. To get more details on the error, use ErrorInfo with the errMessage constant.
- a variable of type DiskFile. If an error occurs, the ErrorOccurred variable is set to True. To get more details on the error, use ErrorInfo with the errMessage constant.
Not available.
<File to manipulate>: Character string Name and full or relative path of the file (up to 260 characters). A UNC path can be used.
<Opening mode>: Optional constant (or combination of constants) Constants used to define the opening mode of the file, the access mode to the file and the lock mode of the file.
Opening an external file and initializing a DiskFile variable Hide the details
<Result> = fOpen(<DiskFile> , <File to manipulate> [, <Opening mode>])
<Result>: Boolean - True if the file was opened and associated with variable of type DiskFile,
- False otherwise. To get more details on the error, use ErrorInfo with the errMessage constant.
<DiskFile>: DiskFile variable Name of the DiskFile variable to be associated with the manipulated text file. <File to manipulate>: Character string Name and full or relative path of the file (up to 260 characters). A UNC path can be used.
<Opening mode>: Optional constant (or combination of constants) Constants used to define the opening mode of the file, the access mode to the file and the lock mode of the file. Remarks Handling errors fOpen throws an error in the following cases: - the file does not exist,
- the file is locked by another computer or by another application,
- the user has no read or write rights on the file to open.
File opening mode By default, if the access mode to the file is not specified, the file is opened according to the file attribute (defined in Windows). An error occurs if the specified access mode does not correspond to the file attribute. A file in "read/write" mode can be opened in all the access modes supported by fOpen (foWrite, foRead and foReadWrite constants). A file in "read-only" mode can only be opened in "read-only" mode (foRead constant). Multiple openings of the same file The same file can be opened several times simultaneously. Each opening is associated with a different file identifier. Each version of the file must be handled individually via its own identifier. Position in the file When opening a file, the current position corresponds to: - the first file byte,
- the last byte of the file is the file is opened in "addition" mode (foAdd constant).
This position can be modified by fSeek. Concatenating several external files To concatenate several external files, you must: - open the destination file in "addition" mode (foAdd constant),
- open the source file in "read-only" mode (foRead or foReadWrite constant),
- read the source file line by line with fReadLine,
- write into the destination file line by line with fWriteLine.
Compatibility between different versions of WINDEV/WEBDEV The foText constant (opening in text mode) and the foBinary constant (opening in binary mode) are not required anymore. They are replaced with the value 0. In this case, fOpen tries to open the file in read/write mode.
Related Examples:
|
Unit examples (WINDEV): Handling text files
[ + ] Handling "text" files with WINDEV: - Create a text file - Write into a text file - Read in a text file
|
|
Unit examples (WEBDEV): Handling text files
[ + ] This example explains how to handle "non HFSQL" files with WEBDEV and it allows you to: - Create a text file - Write into a text file - Read in a text file
|
|
Unit examples (WINDEV Mobile): Handling text files
[ + ] Handling external "text" files: - Create a text file - Write into a text file - Read in a text file
|
Business / UI classification: Business Logic
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|