Results 1 to 9 of 9

Thread: Read entire content of file

  1. #1

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Read entire content of file

    What is the fastest way to read an entire file !

    I did some test and FSO is faster when I use TextStreamObject.ReadAll then using the old Open and looping with Input, which was way slower.

    But I looks like the .ReadAll is limited is size, could that be ?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Read entire content of file

    Try penagate's code in Post #3 of this thread and see what you think.

  3. #3

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Re: Read entire content of file

    Quote Originally Posted by Hack
    Try penagate's code in Post #3 of this thread and see what you think.
    Awesome, thanks Hack,

    Didn't know you could do it in one statement.

    Plus I don't need FSO anymore, wooo hooo !

    One small questions, I always use Integer for the freefile, penagate uses a Long, I guess it should be that way ?

    And does the () make a difference ?

    Thanks a lot

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Read entire content of file

    or use Binary .. its faster than Input:
    VB Code:
    1. Open "C:\path\to\file.txt" For Binary As #1
    2.     tmp = Space(LOF(1))
    3.     Get #1, , tmp
    4. Close #1
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Read entire content of file

    Quote Originally Posted by sebs
    One small questions, I always use Integer for the freefile, penagate uses a Long, I guess it should be that way ?
    I really don't think it makes much of a difference. penagate, like myself, uses long pretty much out of habit even though in many cases integer would work just fine.

  6. #6

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Re: Read entire content of file

    Quote Originally Posted by Static
    or use Binary .. its faster than Input:
    VB Code:
    1. Open "C:\path\to\file.txt" For Binary As #1
    2.     tmp = Space(LOF(1))
    3.     Get #1, , tmp
    4. Close #1
    You mean Get instead of Input ?

    So

    VB Code:
    1. Open "C:\path\to\file.txt" For Binary As #1
    2.     tmp = Space(LOF(1))
    3.     Get #1, , tmp
    4. Close #1
    is faster than

    VB Code:
    1. Open "C:\path\to\file.txt" For Binary Access Read Lock Write As #1
    2.     tmp = Input(1, LOF(1))
    3. Close #1

    ??

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Read entire content of file

    from what I have tested before...

    trying to open a 110MB file.. it was significantly faster....

    well, wait... I was using
    Open "C:\path\to\file.txt" For Input As #1
    for the test...

    never tried it with :
    Open "C:\path\to\file.txt" For Binary Access Read Lock Write As #1

    (And that seems like overkill!!! lol)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Re: Read entire content of file

    Hmm, I have a Overflow error with penagate's code and not Static's code, weird.

    I'll use Static then

    Thanks
    Last edited by sebs; Nov 11th, 2005 at 11:34 AM.

  9. #9
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Read entire content of file

    I used the high-resolution performance timer to test the speeds of these methods.
    The Get method is much faster
    VB Code:
    1. Open "C:\path\to\file.txt" For Binary  Access Read As #1
    2.     tmp = Space(LOF(1))
    3.     Get #1, , tmp
    4. Close #1
    BTW you have an error in the Input method, should be
    VB Code:
    1. Open "C:\path\to\file.txt" For Binary Access Read As #1
    2.     tmp = Input(LOF(1), #1)
    3. Close #1

Posting Permissions

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



Click Here to Expand Forum to Full Width