Link to home
Start Free TrialLog in
Avatar of eNarc
eNarcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I Write a String at the very top of a Text file?

Hi, I'd like to be able to Write to a 100mb file though I'd like to write from the top than to the bottom, I don't want to open the whole file, I just want to write at the top of it.

is there anyway of doing this?
SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eNarc

ASKER

Am I able to Amend/Edit a line?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eNarc

ASKER

so I can edit a line at line 1 without opening up the whole txt file?
Avatar of eNarc

ASKER

if so how could I make that into a function?

editText(filename,line,textToChange);
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eNarc

ASKER

http:#33386934 Geert_Gruwez, because adding text at the bottom I'll have to open the whole file and then rewrite it and then resave it, when thinking about it now, thats how it would be done.

this is because I could read the first 5 lines without actually opening a file which worked really good, though I could add too.


http:#33397823 :Geert_Gruwez

I wasn't aware that it would take that long, thought that it be quicker?


can you rewrite a line without actually opening up the file? like if I wanted to edit a line on 5, could I do that without actually opening the whole file?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eNarc

ASKER

http:#33441677 ThievingSix

so your saying that its like jumping a queue, the line just gets bigger as everyone now has to shifts backwards by 1 and its easier just to go to the back, I see where your going with that, it makes sense.
Avatar of eNarc

ASKER

http:#33441677 ThievingSix

When I try your code it works really fast though it has NUL between each letter.
Avatar of eNarc

ASKER

http:#33388555 systan
when I try your code it sends my cpu to 100% and its been at 100% for about 2 minutes what will the code do?

Avatar of eNarc

ASKER

http:#33385314 Geert_Gruwez

when I use your above code in the lin in the xml format.

the display within the text is this.

<HISTORY>
<ITEM>A</ITEM>
<ITEM>B</ITEM>
<ITEM>C</ITEM>
<ITEM>D</ITEM>
<ITEM>E</ITEM>
< I T E M > A d d e d   I< / H I S


so maybe something is up with my delphi 2009? I don't think I got delphi 7 anymore.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eNarc

ASKER

http:#33443629 Geert_Gruwez >>what you need in the old-fashioned way:

I guess so, it is fast at adding, that way
http://www.delphibasics.co.uk/RTL.asp?Name=Append


http:#33443494 ThievingSix

WriteFileA & INVALID_FILE_HANDLE says invalid

I'll close this solution, I'll just use assignfile write to the end that way