- Managing the 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 format
fOpen (Function) In french: fOuvre Opens an external file (ANSI or UNICODE) in order to handle it by programming. You also have the ability to use fLoadText. Remarks: Versions 18 and later New in version 18 Versions 21 and later New in version 21Syntax
<Result> = fOpen(<File path> [, <Opening mode>])
<Result>: Integer Corresponds to: - 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 the details of the error, use ErrorInfo with the errMessage constant.
<File path>: Character string (with quotes) 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. Remarks Managing the errors fOpen generates 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 proposed 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 by the value 0. In this case, fOpen tries to open the file in read/write.
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
|
This page is also available for…
|
|
|
| |
| | PROCEDURE ReadFile(ArquivoTxt is string, TipoUnicodeToAnsi is string)
//Le arquivo texto INFO(TIMESYS())
// Declare the variables PathFile is string = ArquivoTxt IdFile, ResCloseFile, FileID, NumeroLinha is int Line is string
NextTitle("Atencao")
IF fFileExist(ArquivoTxt) = true
// Open the file FileID = fOpen(PathFile,foReadWrite) IF IdFile = -1 THEN Error(ErrorInfo(errMessage)) ELSE if TipoAnsiUnicode = "UnicodeToAnsi" //Converte de Unicode para Ansi Line = UnicodeToAnsi(fReadLine(FileID)) else Line = fReadLine(FileID) end //Linha 1 NumeroLinha = 1 /// ----COLOQUE AQUI O PROGRESS BAR = 1 //Info("Linha:" + NumeroLinha, Line) ///----------------- LINHA LIDA //Inclua aqui a SUB Procedure de importacao dos dados
WHILE Line <> EOT AND Line <> "" //Proxima linha NumeroLinha += 1 /// ----COLOQUE AQUI O PROGRESS BAR + 1 Line = fReadLine(FileID) //Info("Linha:" + NumeroLinha, Line) ///----------------- LINHA LIDA //Inclua aqui a SUB Procedure de importacao dos dados END IF Line = "" THEN Error(ErrorInfo(errMessage)) IF Line = EOT THEN Info("Final do Arquivo.") ResCloseFile = fClose(IdFile) IF ResCloseFile = -1 THEN //Error(ErrorInfo(errMessage)) END END
ELSE Info("Arquivo não encontrado!") END
info(NumeroLinha,TIMESYS()) |
|
|
|
| |
| |
| |
| |
| |
| |
| | |
|