Open
Opens a file for read or write.
Syntax
Open (Filename, mode, disposition)
Returns
True if the open operation succeeds, False otherwise.
More Information
Mode:
- 0 - Open file in query access mode, attributes maybe queried but the file may not be accessed
- GENERIC_READ - Opens file for reading
- GENERIC_WRITE - Open File for writing
Disposition
- CREATE_NEW - Creates a new file. The function fails if the specified file already exists.
- CREATE_ALWAYS - Creates a new file. The function overwrites the file if it exists.
- OPEN_EXISTING - Opens the file. The function fails if the file does not exist.
- OPEN_ALWAYS - Opens the file, if it exists. If the file does not exist, the function creates the file.
- TRUNCATE_EXISTING - Opens the file. Once opened, the file is truncated so that its size is zero bytes.
Example
This script opens a file (test.txt) on the local C drive and writes 2 lines to it:
Function Main
Dim textfile As Object
Set textfile = File.Connect("127.0.0.1")
If textfile.Open("c:\test.txt", GENERIC_WRITE, CREATE_ALWAYS) Then
textfile.WriteLine("Hi, This is a test file")
textfile.WriteLine("It was created using GFI LanGuard scripting")
textfile.Close
End If
End Function