Constructs a DlxFile object from a path. If the DlxApp.FILEOPEN_OPENDIALOG flag is specified, the dialog box in which to select the file is displayed.
Syntax: |
new DlxFile(fileName)
new DlxFile(fileName, openMode, itemIndex=-1, filters="", initPath="", defExt="")
|
Parameters
Parameter |
Description |
fileName |
Relative or full path of a file. It can also be a URL of a web resource such as a page or file. |
openMode |
File access options for the specified file. Must be one of the following values:
DlxApp.FILEOPEN_READTEXT |
Opens the file for reading as a text file.
Ex: var file = new DlxFile("demo.txt", DlxApp.FILEOPEN_READTEXT);
Opens the file for reading from a web page as a UTF-8 text file.
Ex: var file = new DlxFile("www.mysite.com", DlxApp.FILEOPEN_READTEXT);
|
DlxApp.FILEOPEN_WRITETEXT |
Opens the file in writing as a text file.
Ex: var file = new DlxFile("demo.txt", DlxApp.FILEOPEN_WRITETEXT); |
DlxApp.FILEOPEN_READBINARY |
Opens the file for reading as a binary data file.
Ex: var file = new DlxFile("demo.bin", DlxApp.FILEOPEN_READBINARY);
Opens the file for reading from a web address as a binary data file.
Ex: var file = new DlxFile("www.mysite.com/files/demo.bin", DlxApp.FILEOPEN_READBINARY);
|
DlxApp.FILEOPEN_WRITEBINARY |
Opens the file in writing as a binary data file.
Ex: var file = new DlxFile("demo.bin", DlxApp.FILEOPEN_WRITEBINARY); |
DlxApp.FILEOPEN_ZIP |
Opens the file for writing as a zip-type compressed file. After creating the file you can add the files with the AddFile function.
Ex: var file = new DlxFile("demo.zip", DlxApp.FILEOPEN_ZIP); |
DlxApp.FILEOPEN_UNZIP |
Opens the file for reading as a compressed zip-type file. After opening the file, you can unzip the files with the UnzipFile function.
Ex: var file = new DlxFile("demo.zip", DlxApp.FILEOPEN_UNZIP); |
DlxApp.FILEOPEN_UNZIPTEXT |
Opens the file indicated by
itemIndex for reading as a text file. The file is extracted from a compressed zip-type archive.
Ex: var file = new DlxFile("demo.zip", DlxApp.FILEOPEN_UNZIPTEXT,
1); |
DlxApp.FILEOPEN_UNZIPBINARY |
Opens the file indicated by
itemIndex for reading as a binary data file. The file is extracted from a compressed zip-type archive.
Ex: var file = new DlxFile("demo.zip", DlxApp.FILEOPEN_UNZIPBINARY,
1); |
DlxApp.FILEOPEN_OPENDIALOG |
Opens a dialog box where you can specify the name of the file to open.
|
DlxApp.FILEOPEN_SAVEDIALOG |
Opens a dialog box where you can specify the name of the file to write to.
|
The following values should be used in conjunction with DlxApp.FILEOPEN_OPENDIALOG and DlxApp.FILEOPEN_SAVEDIALOG.
DlxApp.FILEOPEN_ALLFILES |
Specifies that the filter (*.*) that allows all file types to be displayed should be added to the list of file type filters.
|
DlxApp.FILEOPEN_OVERWRITEPROMPT |
To specify that the File Save dialog generates a message box if the selected file already exists.
|
|
itemIndex |
Used in conjunction with the DlxApp.FILEOPEN_UNZIPTEXT and DlxApp.FILEOPEN_UNZIPBINARY modes. Specifies the index of the file contained in the compressed archive. The index must be between 0 and GetItemsCount-1. |
filters |
A series of string pairs that specify filters you can apply to the file. If you specify file filters, only files that match filter criteria will appear in the Files list.
The first string in the string pair describes the filter; the second string indicates the file name extension to use. Multiple extensions may be specified by using a semicolon (the ';' character) as the delimiter.
Each string must be terminated with the vertical bar character "|".
Ex: "Text Files (*.txt)|*.txt|Data Files (*.bin;*.dat)|*.bin;*.dat|"
|
initPath |
The initial directory. |
defExt |
The default file name extension. If the user does not include a known extension (one that has an association on the user's computer) in the Filename box,
the extension specified by defExt is automatically appended to the file name. If this parameter is empty, no extension is appended. |
Remarks
If a full path is not specified, each file path is assumed to be relative to the Drawlogix working directory.
For example, the relative path "myscripts\firstscript.clxjs" is changed to the full path "c:\....\documents\alterlogix\drawlogix\myscripts\firstscript.clxjs".
Example
|
Copy code
|
var filename = "demofile.txt";
// write file
var file = new DlxFile(filename, DlxApp.FILEOPEN_WRITETEXT);
if (file.IsValid())
{
for (var i = 0; i <= 90; i++)
file.Write(i.toString() + "° : " + Math.sin(i / 180 * Math.PI) + "\n");
file.Close();
}
// read file
file = new DlxFile(filename, DlxApp.FILEOPEN_READTEXT);
if (file.IsValid())
{
while (!file.IsEOF())
DlxApp.Printf("%s", file.ReadLine());
file.Close();
}
else DlxApp.Printf("File not found.");
|
See also