henry1 Posted April 10, 2008 Share Posted April 10, 2008 Hello all, I am newbie to Auto It, so please do help me out 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 More sharing options...
TheCuz Posted April 10, 2008 Share Posted April 10, 2008 (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 Edited April 10, 2008 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 More sharing options...
Coolw Posted April 10, 2008 Share Posted April 10, 2008 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 More sharing options...
meekaah Posted April 10, 2008 Share Posted April 10, 2008 hi, and welcome to the forum, i hope this can help #include <File.au3> Dim $array _FileReadToArray("file.txt",$array) _FileWriteFromArray($path,$array,3,0) Link to comment Share on other sites More sharing options...
Coolw Posted April 10, 2008 Share Posted April 10, 2008 (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 April 10, 2008 by Coolw My ProgramsMy WIP'sSteam Server Restarter Link to comment Share on other sites More sharing options...
henry1 Posted April 11, 2008 Author Share Posted April 11, 2008 Thank you all for all the reply I will learn and look into it. Thank you once again Henry Link to comment Share on other sites More sharing options...
henry1 Posted April 11, 2008 Author Share Posted April 11, 2008 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 More sharing options...
Squirrely1 Posted April 11, 2008 Share Posted April 11, 2008 (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 April 11, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
henry1 Posted April 11, 2008 Author Share Posted April 11, 2008 Thank you Squirrely1, So, do you have any idea or solution to the issue? Henry Link to comment Share on other sites More sharing options...
Squirrely1 Posted April 11, 2008 Share Posted April 11, 2008 (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 April 11, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
henry1 Posted April 11, 2008 Author Share Posted April 11, 2008 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 More sharing options...
Squirrely1 Posted April 11, 2008 Share Posted April 11, 2008 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 More sharing options...
henry1 Posted April 11, 2008 Author Share Posted April 11, 2008 Thank you for your information... I will try to look into it Henry Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now