Text file processing

gavrishanchorgavrishanchor Member Posts: 10
Hi,
Is there any funtion available to find no. of lines in a text file. i opened up a text file and set TEXTMODE(True), now how can i find no. of lines in that file (dont want to use LEN function but want to know the end of text file).
thanks in advance

Comments

  • gavrishanchorgavrishanchor Member Posts: 10
    Also how to check whether particular file is already opened or not.
  • Thomas_Hviid_ThornThomas_Hviid_Thorn Member Posts: 92
    Hej gavrishanchor

    1. No. of lines in a text-file
    As stated in the online help
    TEXTMODE (File)
    This function is used to set whether a file should be opened as an ASCII file or a binary file. The function can also be used to determine what the current setting of this option is for a file.
    is TEXTMODE only to open the file as a text-file. E.g. so you can READ with a Text-variable.

    There is - AFSIK - no way of knowning the number of lines in the file upfront.

    2. If a file is in use ?
    The only way I'm aware of, is to copy/rename the file.
    If that succeeds, the file is yours.

    You can use the RENAME/COPY file commands (check F5 - CA/L Symbol Menu under FILE).


    Hope this will help you. May I ask to what you need this ?
    With Kind Regards
    Thoms Hviid Thorn
  • gavrishanchorgavrishanchor Member Posts: 10
    Hi Thomas,
    Thank you so much. anyway i manage to get what i really want.
  • krikikriki Member, Moderator Posts: 9,118
    Also how to check whether particular file is already opened or not.
    Or also:
    IF NOT FileToBeRead.OPEN('The Name') THEN BEGIN
      ERROR('File is in use');
    END;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • gurleengurleen Member Posts: 39
    Hi,
    I have to read till the end of the file. How do I find that out?

    I was trying to check CharCount returned by READ method and stopping when it's zero.The problem with this approach is that if the file has an empty line then the code thinks that the file has ended and does not read all the lines after that.

    count := file.read(line);
    while count > 0 do
    begin
    ....
    .....
    count := file.read(line);
    end;
Sign In or Register to comment.