v10.50 v10.55 Alpha v10.54 Alpha v10.53 Alpha v10.52 Alpha v10.51 Alpha
v10.50 v10.55 Alpha v10.54 Alpha v10.53 Alpha v10.52 Alpha v10.51 Alpha

File Functions

This group of functions covers VSE capabilities to work with external files.

OpenFile()

Opens a file for writing.

OpenFile(file_path, append, mode)

Parameters

file_path

Full path to the file to open. (For ‘\’ use ‘\\’).

append

If present and not equal to 0, specifies that VSE should append
the following write operations to the contents of the file; otherwise, the
contents of the file are cleared.

mode

Specifies the open mode (text or binary) for the file. If omitted, text mode is used. It can be one of the following values:

  • _FO_BINARY (= 0): Opens file in binary mode

  • _FO_TEXT (= 1): Opens file in text mode (default)

Return Values

The "handle" to the file to be used in other file functions.

Example

…
set file_handle = 0;
…
file_handle = OpenFile("D:\\Log.txt");  # Opens file in text mode. 
# The previous contents are erased. 
…
WriteString(file_handle, "Some Text1"); # Write text string to file.
WriteString(file_handle, "Some Text2"); # Write text string to file.
…
CloseFile(file_handle); # Closes the file.
…
# Opens file in text mode.
# The following file operations append to the contents of the file.
file_handle = OpenFile(GetApplicationFolder() + "Log.txt", _APPEND); 
# Opens file in binary mode. The previous contents are erased.
file_handle = OpenFile("D:\\data.bin", 0, _FO_BINARY); 
…
Write(file_handle, 0xAABBCCDD); # Writes integer value into the binary file.
CloseFile(file_handle);         # Closes the binary file.

CloseFile()

Closes an open file.

CloseFile(file_handle)

Parameters

file_handle

File "handle"

Example

…
set file_handle = 0;
…
file_handle = OpenFile("D:\\Log.txt"); # Opens file.
# The previous contents are erased.
…
WriteString(file_handle, "Some Text1"); # Write text string to file.
WriteString(file_handle, "Some Text2"); # Write text string to file.
…
CloseFile(file_handle); # Closes file.
…

WriteString()

Writes a text string to the file.

WriteString(file_handle, text_string)

Parameters

file_handle

File "handle"

text_string

Text string

Remarks

If the file_handle parameter refers to a text file, then a trailing End-Of-Line symbol is added to the text. In case of binary files, the End-Of-Line symbol is not added.

Example

…
set file_handle = 0;
…
file_handle = OpenFile("D:\\Log.txt"); # Opens text file.
# The previous contents are erased.
…
WriteString(file_handle, "Some Text1"); # Write text string to file.
WriteString(file_handle, "Some Text2"); # Write text string to file.
…
CloseFile(file_handle);                 # Close the file.
…

Write()

Writes data to the file.

Write(file_handle, value, num_of_bytes)

Parameters

file_handle

The "handle" to the file previously opened by OpenFile()

value

Data to write to the file

num_of_bytes

(Optional) Specifies how many bytes to take from the value parameter. If omitted, length is calculated automatically based on the value type.

Remarks

This function is primarily for binary files. It can be used for text files only if the value parameter is a string of text. In that case, it is equivalent to the WriteString() function and the num_of_bytes parameter is ignored.

Example

…
set BinFile = 0;
…
BinFile = OpenFile("C:\\data.bin", 0, _FO_BINARY);
…
# Write a string to the binary file.
Write(BinFile, "All we need is love!!!"); 

# Write a substring ("All") to the binary file.
Write(BinFile, "All we need is love!!!", 3); 

val = 0xBEEF;
Write(BinFile, val);    # Writes integer = (EF BE 00 00) to the binary file.
Write(BinFile, val, 2); # Writes WORD = (EF BE) to the binary file.

# Write a byte chain to the binary file.
Write(BinFile, 'AABBCCDDEEFF12345678'); 

# Write a list of values to the binary file.
Write(BinFile, [ 0xAA, "USB", 12, 0xBEEF ]); 
…
CloseFile(BinFile); # Closes the binary file.
…

ShowInBrowser()

This function opens a file in Windows Explorer. If the extension of the file has the application registered to open files with such extensions, it is launched. For instance, if Edge is registered to open files with extension .htm and the file handle passed to ShowInBrowser() function belongs to a file with such an extension, then this file is opened in Edge.

ShowInBrowser (file_handle)

Parameters

file_handle

File "handle"

Example

…
set html_file = 0;
…
html_file = OpenFile("D:\\Log.htm"); 
…
WriteString(html_file, "<html><head><title>LOG</title></head>");
WriteString(html_file, "<body>"); 
…
WriteString(html_file, "</body></html>");
ShowInBrowser(html_file);     # Opens the file in Edge.
CloseFile(html_file);
…