Sign in to follow this  
Followers 0
henry1

Erase multiple line

13 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

hi, and welcome to the forum,

i hope this can help :D

#include <File.au3>
Dim $array
_FileReadToArray("file.txt",$array)
_FileWriteFromArray($path,$array,3,0)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thank you all for all the reply :D

I will learn and look into it.

Thank you once again :D


Henry

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

henry1 - Now is the time for all good men to post the code they are using that gave them:

[Blank line]
Data1
Data2
etc...
Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

Thank you Squirrely1,

So, do you have any idea or solution to the issue?


Henry

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you for your information...

I will try to look into it :D


Henry

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  
Followers 0