Jump to content

Erase multiple line


Recommended Posts

Hello all,

I am newbie to Auto It, so please do help me out :D

I want to Open a file in notepad and basically block the first 3 lines and erase it. Then save it back. My question is how to select and delete the first 3 lines from the top? Any ideas?

Thank you.

Henry

Henry
Link to comment
Share on other sites

First off, welcome!

Second, the help file will have everything that you need. Look up _FileReadToArray, then run through the array created from that function, starting at 3, and put that into a variable, then write the variable to that file using FileWrite.

That should keep you busy for a while :D

Edited by TheCuz

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Link to comment
Share on other sites

I used this

#include <File.au3>
#include <Array.au3>
Dim $avArray[3]
FileOpen("test.txt",0)
_FileReadToArray ("test.txt", $avArray)
If @error = 1 Then
    MsgBox(1,"Error", "File does not exist!")
    Exit
EndIf
For $deletefile = 4 to 0 Step -1
    _ArrayDelete ($avArray, $deletefile)
Next
_ArrayDisplay($avArray)

For a file that said this:

If it works

these 3 lines

will be deleted

lalalalalqala

My ProgramsMy WIP'sSteam Server Restarter
Link to comment
Share on other sites

Sorry, I forgot that you wanted to save it back, so here are the results!

#include <File.au3>
#include <Array.au3>
Dim $avArray[3]
FileOpen("test.txt",0)
_FileReadToArray ("test.txt", $avArray)
If @error = 1 Then
    MsgBox(1,"Error", "File does not exist!")
    Exit
EndIf
For $deletefile = 3 to 0 Step -1
    _ArrayDelete ($avArray, $deletefile)
Next
_FileWriteFromArray ("test.txt", $avArray)

lalalalalqala

Edited by Coolw
My ProgramsMy WIP'sSteam Server Restarter
Link to comment
Share on other sites

Hi,

After I tried it on my computer, it still create a blank line after saving. What step I should write to make that blank line gone?

For example:

After performing the script,

[blank line]

Data1

Data2

etc...

Thank you for help and ideas...

Henry
Link to comment
Share on other sites

henry1 - You have reportedly used some code which reportedly needs fixing. It has been suggested that you post said code so that we may look at it, rather than show you yet another generalized regimen of going about accomplishing what you are trying to accomplish. And since you didn't understand from my earlier post what I was saying, why don't you also post your text file as it appears before you work on it. And also - would you enclose all code and files in code tags?

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Hello,

Well, I just used the code given by the comments above. You can see the code in there. However, after I did some played with it. It worked. I used this code:

#include <File.au3>
#include <Array.au3>
Dim $avArray[5]
FileOpen("c:\test\test1.txt",0)
_FileReadToArray ("c:\test\test1.txt", $avArray)
If @error = 1 Then
    MsgBox(1,"Error", "File does not exist!")
    Exit
EndIf
For $deletefile = 3 to 0 Step -1
    _ArrayDelete ($avArray, $deletefile)
Next
_FileWriteFromArray ("c:\test\test1.txt", $avArray)
_FileWriteToLine ("c:\test\test1.txt", 1, "", 1)

Moreover, I want to read the contents of a certain folders and process the files with a script. Do you have any ideas?

Thank you.

henry

Henry
Link to comment
Share on other sites

henry1Do this -

In the AutoIt help file, navigate to this page:

AutoIt > Function Reference > File, Directory, and Disk Management > FileFindNextFile

And study the example at the bottom of the page. Then study the whole page.

Das Häschen benutzt Radar

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