473,756 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP!! FAST way to read Parts of Big Files

Hi,

I have files I need to read, which contains records with a variable lenght.
What I need to do is Copy a Part of such a File to a new File, based on the
a Begin- and End-record.

I used this functions:
Dim intMyFile As Integer = FreeFile()
FileOpen(intMyF ile, MakePathFile(st rDirS, strFileS), OpenMode.Input,
OpenAccess.Read , OpenShare.Share d, -1)
Do While Not EOF(intMyFile)
strLine = LineInput(intMy File)
If (intX >= intStartRec) And (intX <= intEndRec) Then
strNew = strNew & strLine & vbCrLf
End If
intX = intX + 1
Loop

It worked fine until I met some really big files. I have some files of 10
Mb, containing 75000 records... After 20 minutes my application still
doesn't have read the exact part.
I tryed this:
Dim fsFile As New FileStream(Make PathFile(strDir S, strFileS), FileMode.Open,
FileAccess.Read )
Dim brFile As New StreamReader(fs File,
System.Text.Enc oding.GetEncodi ng(1252), False, fsFile.Length - 1)
intX = 0
Do While intX <= intEndRec
strLine = brFile.ReadLine
If (intX >= intStartRec) And (intX <= intEndRec) Then
strNew = strNew & strLine & vbCrLf
End If
intX = intX + 1
Loop

But it's as slow as the other one.

Only one thing was really quick (only 10 seconds):
Dim fsFile As New FileStream(Make PathFile(strDir S, strFileS),
FileMode.Open, FileAccess.Read )
Dim brFile As New StreamReader(fs File,
System.Text.Enc oding.GetEncodi ng(1252), False, fsFile.Length - 1)
Dim strChar((intEnd Rec * 128) - 1) As Char
For intX = 0 To strChar.Length - 1
strChar(intX) = " "
Next
brFile.ReadBloc k(strChar, intStartRec * 128, (intEndRec - intStartRec) *
128)

But here I had several stupid problems for which I din't really find a
solution:
- first of all: I'm having really big problems converting the Char to a
String (I tryed filing the Char with spaces and than Trim it but what about
spaces in the end of my File?)
- the ReadBlock works with character-positioning, and not with lines. Is
there a way to convert a line-position to a character-position or do a
ReadBlock with lines or something like that?
Anyhelp would really be appreciated!! I'm really stuck with this problem,
and it's kidn of urgent!! Any help regarding the ReadBlock or
StremReader-stuff, or on other (FAST!) way to do this would really be
appreciated!!

Thanks a lot in advance!!

Pieter


Nov 20 '05 #1
4 2064
DraguVaso <pi**********@h otmail.com> wrote:
I have files I need to read, which contains records with a variable lenght.
What I need to do is Copy a Part of such a File to a new File, based on the
a Begin- and End-record.

I used this functions:
Dim intMyFile As Integer = FreeFile()
FileOpen(intMyF ile, MakePathFile(st rDirS, strFileS), OpenMode.Input,
OpenAccess.Read , OpenShare.Share d, -1)
Do While Not EOF(intMyFile)
strLine = LineInput(intMy File)
If (intX >= intStartRec) And (intX <= intEndRec) Then
strNew = strNew & strLine & vbCrLf
End If
intX = intX + 1
Loop

It worked fine until I met some really big files. I have some files of 10
Mb, containing 75000 records... After 20 minutes my application still
doesn't have read the exact part.


The problem is your string concatenation. Either create a StreamWriter
to start with, and just copy the relevant lines straight to disk, or
use a StringBuilder to build up the string in memory.

Just reading through the file should be very fast indeed.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 20 '05 #2
DraguVaso <pi**********@h otmail.com> wrote:
I have files I need to read, which contains records with a variable lenght.
What I need to do is Copy a Part of such a File to a new File, based on the
a Begin- and End-record.

I used this functions:
Dim intMyFile As Integer = FreeFile()
FileOpen(intMyF ile, MakePathFile(st rDirS, strFileS), OpenMode.Input,
OpenAccess.Read , OpenShare.Share d, -1)
Do While Not EOF(intMyFile)
strLine = LineInput(intMy File)
If (intX >= intStartRec) And (intX <= intEndRec) Then
strNew = strNew & strLine & vbCrLf
End If
intX = intX + 1
Loop

It worked fine until I met some really big files. I have some files of 10
Mb, containing 75000 records... After 20 minutes my application still
doesn't have read the exact part.


The problem is your string concatenation. Either create a StreamWriter
to start with, and just copy the relevant lines straight to disk, or
use a StringBuilder to build up the string in memory.

Just reading through the file should be very fast indeed.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 20 '05 #3
Shit :-S
*enormous blush* :-(
I spend 2 hours trying to get it faster and getting frustrated, and I didn't
think about the string-concatenation :-(

Thanks a lot! You made my day! hehe :-)

Pieter

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
DraguVaso <pi**********@h otmail.com> wrote:
I have files I need to read, which contains records with a variable lenght. What I need to do is Copy a Part of such a File to a new File, based on the a Begin- and End-record.

I used this functions:
Dim intMyFile As Integer = FreeFile()
FileOpen(intMyF ile, MakePathFile(st rDirS, strFileS), OpenMode.Input, OpenAccess.Read , OpenShare.Share d, -1)
Do While Not EOF(intMyFile)
strLine = LineInput(intMy File)
If (intX >= intStartRec) And (intX <= intEndRec) Then
strNew = strNew & strLine & vbCrLf
End If
intX = intX + 1
Loop

It worked fine until I met some really big files. I have some files of 10 Mb, containing 75000 records... After 20 minutes my application still
doesn't have read the exact part.


The problem is your string concatenation. Either create a StreamWriter
to start with, and just copy the relevant lines straight to disk, or
use a StringBuilder to build up the string in memory.

Just reading through the file should be very fast indeed.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 20 '05 #4
Shit :-S
*enormous blush* :-(
I spend 2 hours trying to get it faster and getting frustrated, and I didn't
think about the string-concatenation :-(

Thanks a lot! You made my day! hehe :-)

Pieter

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
DraguVaso <pi**********@h otmail.com> wrote:
I have files I need to read, which contains records with a variable lenght. What I need to do is Copy a Part of such a File to a new File, based on the a Begin- and End-record.

I used this functions:
Dim intMyFile As Integer = FreeFile()
FileOpen(intMyF ile, MakePathFile(st rDirS, strFileS), OpenMode.Input, OpenAccess.Read , OpenShare.Share d, -1)
Do While Not EOF(intMyFile)
strLine = LineInput(intMy File)
If (intX >= intStartRec) And (intX <= intEndRec) Then
strNew = strNew & strLine & vbCrLf
End If
intX = intX + 1
Loop

It worked fine until I met some really big files. I have some files of 10 Mb, containing 75000 records... After 20 minutes my application still
doesn't have read the exact part.


The problem is your string concatenation. Either create a StreamWriter
to start with, and just copy the relevant lines straight to disk, or
use a StringBuilder to build up the string in memory.

Just reading through the file should be very fast indeed.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3065
by: googlinggoogler | last post by:
Hiya, The title says it all really, but im a newbie to python sort of. I can read in files and write files no probs. But what I want to do is read in a couple of files and output them to one single file, but then be able to take this one single file and recreate the files I put into it. Im really at a loss as to how I go about recovering the files?
5
13275
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
1
1569
by: Pranav Bagora | last post by:
Hello, I am getting a permission Denied error when i am trying to make changes in some read only files in a directory. How do we check and change the read only attributes of files in python. Please Help, Pranav
2
1435
by: Michael A. Covington | last post by:
I want to deploy a project in which the user is provided with a set of READ-ONLY files to use as templates. They will be in a directory to which the user can add files of his own. It's important to keep the user from deleting any of the pre-supplied files, because if this is done, the Windows Installer apparently wants to "repair" the application. I didn't realize it kept track of such things, but it's doing so. How can I make the...
2
2626
by: ViperCB | last post by:
Hello from a newbie, I am trying to do some research on an upcoming project that involves reading in audio files of various formats and using the audio signal as a source of noise to generate pretty pictures. (like windows media player visual plugins. I will be developing in C++ and was wondering if there are any packaged libraries out there that I can use to read audio files encoded in different formats and lets me easily access the...
2
9988
by: hzgt9b | last post by:
Using VB .NET 2003, I need to delete some read-only files. I tried using System.IO.File.Delete(filename) - but when the files are read-only, I get error messages stating that I don't have proper access... So, what's the best way to delete a read-only file programmatically? Any help would be greatly appreciated!
0
1064
by: Ivt22 | last post by:
hi, if someone can help me how can i read all files form a CD one by one and from each file extract all tables in the file once the file ends go and open the next file and on and on... until the last file in the CD. I can do it for one file and the extraction of a table too, so , if anybody can help me... thanks,
0
2165
by: U S Contractors Offering Service A Non-profit | last post by:
This Sunday the 26th 2006 there will be Music @ Tue Nov Inbox Reply Craig Somerford to me show details 9:54 pm (26 minutes ago) #1St "CLICK" HeAt frOm A blanket --http://mail.google.com/mail/?realattid=f_3n2tmv&attid=0.1&disp=inline&view=att&th=10f0d56e8cb478be 24 oct 2006
0
1266
by: kdsutaia | last post by:
hi! I hv to read two files from two diff directories and need to count pairs of words from both the files. as well I hv to keep track of no of documents where this terms present. All files are .xml files.. I am reading using saxparser. I was thinking using hashtable where keys are pair words and value will be the vector which contains word freq and doc freq. can any one suggest better approch then this. Secondly, How do i read two...
14
5770
by: Zoro | last post by:
My task is to read html files from disk and save them onto SQL Server database field. I have created an nvarchar(max) field to hold them. The problem is that some characters, particularly html entities, and French/German special characters are lost and/or replaced by a question mark. This is really frustrating. I have tried using StreamReader with ALL the encodings available and none work correctly. Each encoding handles some characters...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.