|
|
|
|
- Handling errors
- Operating mode in Windows Vista (and later)
- Opening mode of file
- Multiple openings of the same file
- Position in the file
- Concatenating several external files
- Compatibility between the different versions of WINDEV/WEBDEV
- Locking and unlocking
- Managing text files in UNICODE
fOpen (Function) In french: fOuvre Opens an external file (ANSI or UNICODE) in order to handle it through programming. You can also use fLoadText. Remarks: New in version 28 Syntax
<Result> = fOpen(<File path> [, <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 the external files.
- -1 if an error occurred. To get more details on the error, use ErrorInfo with the errMessage constant.
New in version 28a 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 path>: Character string Name and full (or relative) path of 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 mode of file:
| | foAdd | Open the file in "addition" mode. At opening, the current position corresponds to the last byte of the file. | foCreate | Create the file. If the file already exists (same name, same directory), this file is deleted and recreated. | foCreateIfNotExist | Create the file only if this file does not exist. The current position corresponds to the first byte of the file. |
- Access mode to the file. This type is used by fReadLine and fWriteLine to define the type of information to read and write in the external file:
- File locking mode:
| | foAutomaticDeletion | The file is locked when opened, and will be automatically deleted when closed (when fClose is called, or when the application is closed). If multiple applications are using the file, it will be automatically deleted when the last application closes it (when fClose is called, or at the end of the application).
This constant is not available.
The file will not be deleted if it is being used by another application when it is closed (when fClose is called, or when the application is closed). | foRead | Open the file in "read-only" mode. This file can only be read. | foReadLock | The other applications cannot read the current file.
    This constant is not available. | foReadWrite (Default value) | Open the file in "read/write" mode. This file can be read and modified (equivalent to foRead+foWrite). | foWrite | Open the file in "write-only" mode. This file can only be modified.
  This constant is not available. | foWriteLock | The other applications cannot modify the current file.
    This constant is not available. |
- Other options:
| | foSequentialAccess | Optimizes the management of caches for the file by specifying to Windows that the file will be read from the beginning to the end.
   This constant is not available. |
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.
- a Unicode string was used for <File path> in an operating system such as Windows 98 or Windows Me.
Remark: The opening in modification of a file found in a write-protected diskette is successful. Opening mode of file 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 the 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. Business / UI classification: Business Logic
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|