Jump to content
Sign in to follow this  
WifiHero

Delete a line from a file?

Recommended Posts

WifiHero

Is there some way to? I have tried just about everything ><

$file = FileDelete("Txt.txt" 1)

And ect.

Any ideas?

Share this post


Link to post
Share on other sites
Paulie

_FileWriteToLine()

Share this post


Link to post
Share on other sites
WifiHero

_FileWriteToLine()

Be abit more specific? Tried it and it didnt work.

EDIT:

Tried $_FileWriteToLine("txt.txt",1) $_FileWriteToLine("txt.txt"), $_FileWriteToLine()

And more, But didnt get any results.

Edited by WifiHero

Share this post


Link to post
Share on other sites
Paulie

Open the Help File.

_FileWriteToLine

--------------------------------------------------------------------------------

Writes text to a specific line in a file.

#Include <File.au3>
_FileWriteToLine($sFile, $iLine, $sText[, $fOverWrite = 0])

Parameters

$sFile - The file to write to

$iLine - The line number to write to

$sText - The text to write

$fOverWrite - If set to 1 will overwrite the old line, If set to 0 will not overwrite

Remarks

If _FileWriteToLine is called with $fOverWrite as 1 and $sText as "", it will delete the line.

Example:

#Include <File.au3>
_FileWriteToLine("txt.txt", 2, "",1) ;will delete the second line of file
Edited by Paulie

Share this post


Link to post
Share on other sites
WifiHero

Open the Help File.

Example:

#Include <File.au3>
_FileWriteToLine("txt.txt", 2, "",1) ;will delete the second line of file
No disrespect man...But it didnt work.

Share this post


Link to post
Share on other sites
Cater

It works but if you have file like that:

1

2

3

4

5

if you use this: _FileWriteToLine("txt.txt", 2, "",1)

file will looks like that

1

2

4

5

but if you want empty space in 3 line you can use this: _FileWriteToLine("txt.txt", 2, " ",1)

and file will looks like that:

1

2

4

5

but there will be 1 space.

Share this post


Link to post
Share on other sites
WifiHero

It works but if you have file like that:

1

2

3

4

5

if you use this: _FileWriteToLine("txt.txt", 2, "",1)

file will looks like that

1

2

4

5

but if you want empty space in 3 line you can use this: _FileWriteToLine("txt.txt", 2, " ",1)

and file will looks like that:

1

2

4

5

but there will be 1 space.

Thats preciclly how I want it to be, But the problem is, All I get when I put in the code is -error, unreconized command-

And it does nothing.

EDIT:

As in I want it to remove it without a space remaining.

Edited by WifiHero

Share this post


Link to post
Share on other sites
herewasplato

...if you use this: _FileWriteToLine("txt.txt", 2, "",1)

file will looks like that

1

2

4

5...

I would hope that it would lokk like:

1

3

4

5

:-)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
nobbe

i did it like this

#include <String.au3>

Local $f_in = @ScriptDir & "\error.log";
Local $f_out = @ScriptDir & "\error.new";

Local $oldline = "";

$fh_in = FileOpen($f_in, 0)
$fh_out = FileOpen($f_out, 2) ; write

; Check if file opened for reading OK
If $fh_in = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    exit;
EndIf


While 1
    $line = FileReadLine($fh_in)
    If @error = -1 Then ExitLoop
    
    If StringInStr($line, "TEST") > 0 Then ; dont write out TEST

        ConsoleWrite($line & @CRLF);
    else
        FileWriteLine($fh_out, $line); all other lines 
    


        
    EndIf
WEnd

FileClose($fh_in)
FileClose($fh_out)

FileMove ($f_in ,  @ScriptDir & "\error.lo1");
FileMove ($f_out,  @ScriptDir & "\error.log");

Share this post


Link to post
Share on other sites
herewasplato

...All I get when I put in the code is -error, unreconized command-...

Did you use

#Include <File.au3>

...and what version of AutoIt are you using?

#include <File.au3>
_FileWriteToLine("temp.txt", 2, "", 1)
works fine with v3.2.12.0

[size="1"][font="Arial"].[u].[/u][/font][/size]

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.