Results 1 to 4 of 4

Thread: End of file

  1. #1
    Join Date
    Oct 2006
    Location
    I'm a figment of your imagination
    Posts
    422
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    End of file

    The problem:

    I need to open a file and read it as string till the end of the file. How could I do something like that? I know how to open files, and how to read a certain # of characters of it, but not how to get to the end of the file without causing a memory access violation. Any help?

    The code so far:

    SCAR Code:
    function ReadFile(fileno : integer): string;
    var
      i: integer;
    begin
      repeat
      ReadFileString(fileno, result, i);
      i:= i+1;
      until(EndOfFile(fileno)=true);
    end;

    It's been a while... but I'm BACK!!!

  2. #2
    Join Date
    Oct 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    Filenum:= OpenFile(Path, true);
    if(Filenum >= 0)Then
      Begin
        ReadFileString(Filenum, TheString, FileSize(Filenum));
      End;
    CloseFile(Filenum);

    Try that maybe... You're thinking about reading bytes, not strings. A byte would be like the key "a" or w/e (i think atleast), a string is "asdflkjhadslkfjahlskdjhfaskgnuwiglaksdjnfg" but could also be "a" if written correctly.

  3. #3
    Join Date
    Oct 2006
    Location
    I'm a figment of your imagination
    Posts
    422
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    TYVM!!! This stuff really helped me out. Didn't know there was a FileSize Function. Thanks a lot!

    It's been a while... but I'm BACK!!!

  4. #4
    Join Date
    Apr 2006
    Location
    I live in NH
    Posts
    611
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    You can just try this function if you like. Just type in ReadFile and then the path to the file and run the script.

    Code:
    function ReadFile(Path : String) : String;
    var
      FileNum : Integer;
      Text : String;
    begin
      FileNum := OpenFile(Path, True);
      if(Filenum > -1)then
      begin
        ReadFileString(Filenum, Text, FileSize(FileNum));
      end;
      CloseFile(FileNum);
      Result := Text;
    end;
    ~Ron

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help with log file.
    By l33t_h4x0r in forum OSR Help
    Replies: 2
    Last Post: 10-10-2007, 11:49 AM
  2. sig from file
    By skibby in forum Semi Stupid Pictures
    Replies: 6
    Last Post: 05-26-2007, 04:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •