File functions




uFileInfo

Description

Returns information about a file. When uFileInfo is set to EXISTS the function returns the whole path to the file if it exists or an empty string if it does not exist. uFileInfo is set to SIZE the size of the file is returned or an empty string if the file does not exist.

NoteBe aware that you have to double the backslashes in JavaScript environments because the backslash is used as escape sequence.

Syntax

string uFileInfo (file [, infotype])

Parameters

string file

The file to investigate.

string infotype (optional)

The type of information to retrieve. The default is EXISTS.

Examples

Example 1

To retrieve file information in JavaScript Calculator:

uFileRead("C:\\windows\\notepad.exe") // returns C:\windows\notepad.exe.
uFileRead("C:\\win\\notepad.exe") // returns C:\windows\notepad.exe.
uFileRead("C:\\windows\\notepad.exe", “SIZE”) // returns 68608.



uFileRead

Description

Returns the content of a file.

Syntax

string uFileRead(URL [, bytes] [, offset] [, encoding])

Parameters

string URL

The URL specifying the source to read

integer bytes (optional)

The number of bytes to read. The default is 0, which means the whole file.

integer offset (optional)

The number of bytes to skip from the beginning of the file. The default is 0.

Examples

Example 1

To access local files:

uFileRead("c:\myFile.txt”)
uFileRead(“/home/testuser/myfile.txt”)
uFileRead(“file:///c:/myFile.txt”)

Example 2

To read files from a Windows share:

uFileRead(“\\fileserver\freeShare\testfile.txt”)

Example 3

To read content of a file from HTTP and HTTPS

uFileRead("http://http://www.google.com/search?hl=en&q=pizza&btnG=Google+Search")
uFileRead("https://http://www.google.com/search?hl=en&q=pizza&btnG=Google+Search")

Example 4

To read content of a file from FTP:

uFileRead("ftp://myUser:myPasswd@myServer/data/myFile.txt")



uFileWrite

Description

Allows you to write data to a file. If no URL is given, the data is written to a file write.log in the Sybase IQ ETL log directory.

Syntax

string uFileWrite(data [, URL] [, append] [, encoding])

Parameters

string data

The data to be written.

string URL (optional)

The URL for file access and location.

number append (optional)

Flag (0/1) indicating if the data should be appended or not.

string encoding (optional)

The encoding of the target file.

Examples

Example 1

To write data to a file via CIFS:

uFileWrite("hello", "//myServer/myShare/data/test.txt")