Options

Merge two textfiles?

StormStorm Member Posts: 27
Hi

I want to merge two textfiles via. Navision and have done it so far by writing a SHELL command:
SHELL('cmd','/C','copy '+File1+'+'+File2 +' '+NewFile);
Can't you do this without using the SHELL command?

When the two files are merged it also seems that a (It looks like an arrow pointing right in a binary texteditor) appears at the end of the new file. Why is that? and how do you get rid of it?
Have tried:
FileVar.OPEN(NewFile);
FileVar.SEEK(FileVar.LEN-1);
FileVar.TRUNC;
Can someone help me?

Thanks

/H.

Comments

  • GrantGrant Member Posts: 30
    It looks like you've got the right idea. You may have to open up the file in binary mode rather than text mode. Try this :

    FileID.WRITEMODE(TRUE);
    FileID.TEXTMODE(FALSE);
    FileID.OPEN(FullExportFilename);
    FileID.SEEK(FileID.LEN-1);
    FileID.TRUNC;
    FileID.CLOSE;
  • rspruitrspruit Member Posts: 25
    For the copying you could do:

    1) copy the file first file to the new file with FILE.COPY
    2) open the new file with a FILE variable
    3) open the second file with a FILE variable
    4) read the lines of the second file and write them to the new file

    I think if the strange character was there in the input files only then it will occur in the output (new) file? Are the files text only?

    Grtz.

    Remco
  • krikikriki Member, Moderator Posts: 9,120
    Try :
    SHELL('cmd','/C','copy '+File1+' /B +'+File2 +' /B '+NewFile + ' /B');
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • StormStorm Member Posts: 27
    Hey again

    Thanks for your replies.

    I've at long last solved it...

    I had to use the SHELL command but the reason why I couldn't get the TRUNC function to work was simply because the system couldn't copy the files fast enough before executing the rest of the code, so I had to put in a SLEEP right after the SHELL command... it took me pretty long time to figure that out :-)

    Thanks again
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    An IF SHELL - THEN is a better idea.
Sign In or Register to comment.