Reads a file in CSV format (comma-separated format) into memory. After the file has been read, the whole file is accessible without further I/O. The file is read into shared memory only once at a client machine, even if it is read by multiple virtual users. Usually you will use this function only once in your script for each file you load for example, in a start up transaction that initializes your simulation.
If the file name includes a directory name, the file is opened in the specified directory. Otherwise, Silk Performer searches for the file in the directory where the test script is located, in the data directory, in the results directory and in the project directory.
Kernel.bdh
FileCSVLoad( out hFile : number, in sFileName : string, in sSeparator : string optional, in sDelimiter : string optional ): boolean;
true if successful
false otherwise
Parameter | Description |
---|---|
hFile | Variable receiving the file handle used to access the file |
sFileName | Specifies the path and file name of the file to read. If you specify a file name without path information, Silk Performer searches for the file in the user data directory specified in the Directories tab of the System Settings - Workbench dialog. |
sSeparator | Specifies the separator of the columns you want to use (optional). Usually the separator for CSV-formatted files is the comma (","). |
sDelimiter | Specifies the delimiter you want to use for identifying a separator/delimiter sign within a data field (optional). By default the delimiter is the double quotes sign ("). |
Name | Nickname | Address | City |
---|---|---|---|
John Smith | John ““The Tester”” | “Fast Lane, 1432” | Test City |
Since double quotes are the delimiter, the double quotes in the Nickname need to be preceded by the delimiter itself (in this case the delimiter has the same functionality as for example a backslash has in BDL code).
The address field includes a comma, which is usually the separator. To prevent FileCSVLoad from using this comma as a separator, the value of John Smith’s address must be encompassed by the delimiter (“…”).
var hFile, r: number; dcltrans transaction TInit begin ... FileCSVLoad(hFile, "login.csv", ",", "\""); end TInit; transaction TMain begin r := FileGetNextRow(hFile); ... end TMain;