Files

Function

Description

uFileInfo

Returns information about a file

uFileRead

Reads data from a file

uFileWrite

Writes data to a file




uFileInfo

Description

Returns information about a file. When infotype 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. Is infotype set to SIZE, the size of the file will be 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 kind of information to get. Default is EXISTS.

Examples

Example 1

Getting file information

uFileInfo("C:\\windows\\notepad.exe") // returns
C:\windows\notepad.exe
uFileInfo("C:\\windows\\notepad.exe","SIZE") // returns 68608



uFileRead

Description

Reads data from a file

Syntax

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

Parameters

string URL

URL specifying the source to read

integer bytes (optional)

Number of bytes to read. Default is 0, means the whole file

integer offset(optional)

Number of bytes to skip from the beginning of the file. Default is 0.

string encoding(optional)

The encoding of the data source. Default encoding is ISO8859-1

Examples

Example 1

Accessing local files

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

Read files from a Windows share

uFileRead("\\\\fileserver\\freeShare\\testfile.txt")

Read the content of a file via 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")

Read the content of a file via FTP

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



uFileWrite

Description

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

Syntax

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

Parameters

string data

The data to be written

string URL (optional)

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

Write data to a file via CIFS

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