Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I use the SilkTest file functions to add information to the beginning of a file?

How can I use the SilkTest file functions to add information to the beginning of a file?

As of SilkTest 5.5 SP1, there is no file open mode that allows you to insert information into the beginning of a file. If you use FM_UPDATE, you can read in part of your file before writing, but any write function calls will overwrite the rest of the file.

If you are writing strings rather than structured data, you can use ListRead() and ListWrite() to easily insert information at the beginning (or any other point) of a file . Use ListRead() to read the contents of the file into a list, insert the new information at the head (or any other point) of the list, and use ListWrite() to write it back out. For example:

"> [-] LIST OF STRING lsNewInfo = {...}
[ ] "*New line one*"
[ ] "*New line two*"
[ ] "*New line three*"

[ ] LIST OF STRING lsFile
[ ] INTEGER i
[ ]
[ ] ListRead (lsFile, "{GetProgramDir ()}\Sample.txt")
[-] for i = 1 to ListCount (lsNewInfo)
[ ] ListInsert (lsFile, i, lsNewInfo)
[ ] ListWrite (lsFile, "{GetProgramDir ()}\Sample.txt")
[ ]

Sample.txt before:
Line 1
Line 2
Line 3
Line 4
Line 5

Sample.txt after:
*New line one*
*New line two*
*New line three*
Line 1
Line 2
Line 3
Line 4
Line 5

Old KB# 22484

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:32
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.