Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace text in large text file

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
Hi All.
I know I have done this in the past but it has been a while.

I need to replace every occurance of a folder path inside a text file with an alternate path. The text files can run just over 16 meg in size. I know there are methods that are more efficient when working with large files but do not remember what they are.

Anyone have code for doing this before I go reinvent it?
I know it's basically open file, open output file, read input/replace text, write to output file and handle renaming/deleting the files when done. I just want to make it as efficient as is reasonable.

Thanks.

At my age I still learn something new every day, but I forget two others.
 
Hallo,

Can you open it as a TextStream and use ReadAll to load it into a string, then do your replace stuff and write it back in one go?

- Frink
 
I suspect so but the files go up to 16 meg in size and I did not know how well TextStream and ReadAll would work with that large amount of data.

It seems I remember there being a method similar to this but where you can state a number of lines to read in at one time with the benefit of increased performance and able to handle larger files.
I may be remembering this from some other scripting language though.

At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top