Jump to content
Sign in to follow this  
trunc.ate

Writing first line of a text file

Recommended Posts

trunc.ate

I'd like to do a search and replace in a text file dependent on what's in the first line of this file.

This works nicely with FileReadLine($SourceFile, 1).

But at the end of the operation I want to update the first line of the text file. FileWriteLine works different as it only appends a line at the end of the file; is there a way to write the first line?

Share this post


Link to post
Share on other sites
Xenobiologist

HI,

_ReplaceStringInFile

in the helpfile.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
trunc.ate

But when I get this right, _ReplaceStringInFile can't especially write the first line if it doesn't know what's in it at first?

Share this post


Link to post
Share on other sites
BrettF
SmOke_N

_FileWriteToLine should do wat u want

That or:

$hFile = 'FileName and Location'
$sRead = FileReadLine($hFile, 1)
$sReplacement = $sRead & 'Something I want to add'
_ReplaceStringInFile($hFile, $sRead, $sReplacement, 0, 0)
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
trunc.ate

Brilliant, works like a charm. Thanks guys!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.