Jump to content

Delete a line from a file?


Recommended Posts

_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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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");
Link to comment
Share on other sites

...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]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...