cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Pilgrim

Problem with List or END_OF_LIST

Hello All,

I'm having an issue with a list, or maybe end_of_list and i suspect it may be a bug, either that or i have to set some indexing or something... The code below is simply copying text from one file and writing it to another. However, it duplicates the last line. Any ideas? It's driving me mad and i'm about to log a bug with Flexera.

Please advise. TIA!


	
OpenFileMode (FILE_MODE_NORMAL);

if (OpenFile(nvFileHandleSource, sSourcePath, sSourceFile) < 0) then

else

//Create list of strings from file.
FileList = ListCreate(STRINGLIST);
while (GetLine (nvFileHandleSource, svLineSource) = 0)
ListAddString (FileList, svLineSource, AFTER);
endwhile;

endif;


//Open source file for setting strings.
OpenFileMode (FILE_MODE_APPEND);

if (OpenFile(nvFileHandleDest, sDestPath, "\\DeviceLink.xml") < 0) then
MessageBox ("3 Opening of: DeviceLink.xml failed. Manual xml file configuration required.", WARNING);

else

nResult = ListGetFirstString(FileList, szFirstLineDest);
WriteLine(nvFileHandleDest, szFirstLineDest);


while (nResult != END_OF_LIST)
nResult = ListGetNextString (FileList, svLineDest);
WriteLine(nvFileHandleDest, svLineDest);
endwhile;


endif;

ListDestroy (FileList);



Here is the content of the file:



false
false
5
Datascope.DatascopeDevice
Datascope

















And it's duplicating the at the end of the file. Any ideas?
Labels (1)
0 Kudos
5 Replies
Highlighted
Pilgrim

Re: Problem with List or END_OF_LIST

If you display the list populated from the source file with SdShowInfoList, is the list correct at that point? (There's also ListReadFromFile, which could simplify that part.)

In the second part, if you display each string before calling WriteFile, does the last line get displayed twice?

Probably doesn't have a bearing on the issue, but you might call CloseFile when you're done reading and writing each file.
0 Kudos
Highlighted
Pilgrim

Re: Problem with List or END_OF_LIST

Hello Robert,

Thank you for replying. I can always count on you. I have had a chance to try the sd.... but i can say that when i put a messagebox in the while statement, it does display the item twice.

I'll try what you suggested here, but i suspect it's not going to make a difference. I wonder if there is some escape sequence in somehow? I just can't put my finger on it. I'll give it a shot tomorrow morning and see what happens.
0 Kudos
Highlighted
Pilgrim

Re: Problem with List or END_OF_LIST

So i tried ListReadFromFile and ListWritetoFile it doesn't duplicate that end tag. But, it also does use the FILE_MODE_APPEND either, so i get a file with just the text i wrote, it overwrites everything else in the file.

This repeating of the last string in the list is certainly a bug. Is there a place i can log the bug?
0 Kudos
Highlighted
Pilgrim

Re: Problem with List or END_OF_LIST

Would still like to report that bug, but....

I found a workaround to the writing extra last line and append issue. Use ListWriteToFileEX instead:

ListWriteToFileEx(FileList, sDestPath + "\\DeviceLink.xml", LWTF_OPTION_APPEND_TO_FILE);
0 Kudos
Highlighted
Pilgrim

Re: Problem with List or END_OF_LIST

I haven't had a chance to run a test, but what happens if you swap the order of these two lines inside the while loop?

nResult = ListGetNextString (FileList, svLineDest); 
WriteLine(nvFileHandleDest, svLineDest);


In the current order, ListGetNextString will return END_OF_LIST, but WriteLine will be called again with the last value of svLineDest.

P.S. Good find about ListWriteToFileEx. I'd forgotten that existed!
0 Kudos