voidale Posted January 30, 2010 Share Posted January 30, 2010 Hey guys trying to do this for few hours no luck, what i want to do is open txt file copy the 8 first line delete it and delete the space, so next time the 8 lines will be the 8-16 save the file. create another txt file or open and paste it over there sounds easy right? here is what i came up so far can you help? ; Script Start - Add your code below here ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) $answer = MsgBox(4, "first", "This script will run now. Run?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(0, "AutoIt", "OK. Bye!") Exit EndIf ;Run txt Do $x=1 To 8 $ReadLine=FileReadLine("to.txt",$x) ConsoleWrite($ReadLine & @CRLF) ClipPut( $ReadLine & @CRLF) Next i don't have a clue if it works i can't see the txt file and how to copy it? Link to comment Share on other sites More sharing options...
JohnOne Posted January 30, 2010 Share Posted January 30, 2010 (edited) Not sure what you mean about the 8-16 but if you dont want to delete the $file then dont run the code with it in. $file = "to.txt" For $i = 1 To 8 $read = FileReadLine($file,$i) ConsoleWrite($read & @CRLF) Next FileDelete(($file) EDIT: schoolboy error Edited January 30, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted January 30, 2010 Share Posted January 30, 2010 Look in the help file for _FileWriteToLine. In the remarks it says:If _FileWriteToLine is called with $fOverWrite as 1 and $sText as "", it will delete the line.Therefore if you set $iLine = 1, then it should delete the first line. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted January 31, 2010 Share Posted January 31, 2010 Is this what you want?#include <File.au3> ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) $answer = MsgBox(4, "first", "This script will run now. Run?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(0, "AutoIt", "OK. Bye!") Exit EndIf ;Run txt For $x=1 To 8 $ReadLine=FileReadLine("to.txt", 1) ; Read the first line. _FileWriteToLine("to.txt", 1, "", 1) ; Delete the first line. FileWriteLine("output.txt", $ReadLine) ; Append the line in the output file. NextBy the way I noticed in your code that you have combined the terms 'Do' with 'Next'. They do not belong together like that. Loops using 'Do' must be terminated with the word 'Until' followed by an expression to trigger an escape from the loop. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
voidale Posted January 31, 2010 Author Share Posted January 31, 2010 thanks guys for the help didn't expected to get replys so fast, what i want to do is to Copy from that txt file the first 8 lines and past them over another txt file now i want this to repeat so lets say i have 1000 lines over to.txt want it to copy from to.txt 8 lines past over the other file close it all and then again repeat but to take the next 8 lines so first time it takes 1-8 second time 8-16 and then 16-24 is it possible? Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2010 Share Posted January 31, 2010 For $x=1 To 8 $ReadLine=FileReadLine("to.txt", 1) ; Read the first line. _FileWriteToLine("to.txt", 1, "", 1) ; Delete the first line. Next I was going to put something similar in, but could not figure if it would recount the lines after each write and fuff up somehow. was thinking maybe 8 To 1 Step -1 I dont know how that would work. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted January 31, 2010 Share Posted January 31, 2010 thanks guys for the help didn't expected to get replys so fast, what i want to do is to Copy from that txt file the first 8 lines and past them over another txt filenow i want this to repeat so lets say i have 1000 lines over to.txt want it to copy from to.txt 8 linespast over the other file close it all and then again repeat but to take the next 8 lines so first time it takes 1-8 second time 8-16 and then 16-24 is it possible?If you repeat the process you will just recreate an exact copy of the original file. I must be missing something. Perhaps you could explain a little more about how you want the output to appear. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted January 31, 2010 Share Posted January 31, 2010 I was going to put something similar in, but could not figure if it would recount the lines after each write and fuff up somehow.was thinking maybe 8 To 1 Step -1I dont know how that would work.I think an error may occur if you hit the end of the file before completing the process. If the number of lines is constant and divisable by 8 then there shouldn't be a problem. Otherwise some escape mechanism will have to be employed. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2010 Share Posted January 31, 2010 (edited) I cant really think of a reason for this myself But maybe something like this Local $Sourcefile = "from.txt" Local $destinationfile = "to.txt" Local $aFileLines[8] For $i = 1 To 8 $read = FileReadLine($Sourcefile,$i) $aFileLines[$i] = $read Next For $x=1 To 8 _FileWriteToLine($Sourcefile, 1, "", 1) Next For $i = 1 To 8 FileWriteLine($destinationfile,$aFileLines[$i]) Next The count should always be 1 - 8 as the lines are getting deleted Edited January 31, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
voidale Posted January 31, 2010 Author Share Posted January 31, 2010 If you repeat the process you will just recreate an exact copy of the original file. I must be missing something. Perhaps you could explain a little more about how you want the output to appear.yes but in the newer txt file i will have 8 lines this is what i need get 8 lines from to.txt to another txt everytime like this:step 1copy 1-8 lines from "to.txt"step 2past it over to "ftext.txt save & closestep 3 repeat now from 8-16 lines every repeat another 8 linesi know it will be the same as the original but this is how i need it Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2010 Share Posted January 31, 2010 lol copy/paste AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
voidale Posted January 31, 2010 Author Share Posted January 31, 2010 I cant really think of a reason for this myself But maybe something like this Local $Sourcefile = "from.txt" Local $destinationfile = "to.txt" Local $aFileLines[8] For $i = 1 To 8 $read = FileReadLine($Sourcefile,$i) $aFileLines[$i] = $read Next For $x=1 To 8 _FileWriteToLine($Sourcefile, 1, "", 1) Next For $i = 1 To 8 FileWriteLine($destinationfile,$aFileLines[$i]) Next The count should always be 1 - 8 as the lines are getting deleted This one looks like what i need but i get this error "==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $aFileLines[$i] = $read ^ ERROR >Exit code: 1 Time: 0.491 " Link to comment Share on other sites More sharing options...
czardas Posted January 31, 2010 Share Posted January 31, 2010 I cant really think of a reason for this myself But maybe something like this Local $Sourcefile = "from.txt" Local $destinationfile = "to.txt" Local $aFileLines[8] For $i = 1 To 8 $read = FileReadLine($Sourcefile,$i) $aFileLines[$i] = $read Next For $x=1 To 8 _FileWriteToLine($Sourcefile, 1, "", 1) Next For $i = 1 To 8 FileWriteLine($destinationfile,$aFileLines[$i]) Next The count should always be 1 - 8 as the lines are getting deleted Array variable has incorrect number of subscripts. Local $aFileLines[9] operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2010 Share Posted January 31, 2010 Never been hot on arrays try that Local $Sourcefile = "from.txt" Local $destinationfile = "to.txt" Local $aFileLines[8] $aFileLines[0] = "" For $i = 1 To 8 $read = FileReadLine($Sourcefile,$i) $aFileLines[$i] = $read Next For $x=1 To 8 _FileWriteToLine($Sourcefile, 1, "", 1) Next For $i = 1 To 8 FileWriteLine($destinationfile,$aFileLines[$i]) Next AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
GEOSoft Posted January 31, 2010 Share Posted January 31, 2010 (edited) Or $aText = StringRegExp(FileRead("from.txt"), "(?i)(.+)(?:\v)+", 3) If NOT @Error Then For $i = 0 To 7 FileWriteLine("to.txt", $aText[$i]) Next EndIf Edited January 31, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
voidale Posted January 31, 2010 Author Share Posted January 31, 2010 (edited) Never been hot on arrays try that Local $Sourcefile = "from.txt" Local $destinationfile = "to.txt" Local $aFileLines[8] $aFileLines[0] = "" For $i = 1 To 8 $read = FileReadLine($Sourcefile,$i) $aFileLines[$i] = $read Next For $x=1 To 8 _FileWriteToLine($Sourcefile, 1, "", 1) Next For $i = 1 To 8 FileWriteLine($destinationfile,$aFileLines[$i]) Next new error Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $aFileLines[$i] = $read ^ ERROR >Exit code: 1 Time: 0.227 Or $aText = StringRegExp(FileRead("from.txt"), "(?i)(.+)(?:\v)+", 3) If NOT @Error Then For $i = 0 To 7 FileWriteLine("to.txt", $aText[$i]) Next EndIf This one worked but the lines from from.txt, are 1 line over the to.txt gotta add enter? and can you do it will delete the 8 that just copied from "from.txt" so if you repeat it the next 8 will be new lines Edited January 31, 2010 by voidale Link to comment Share on other sites More sharing options...
czardas Posted January 31, 2010 Share Posted January 31, 2010 yes but in the newer txt file i will have 8 lines this is what i need get 8 lines from to.txt to another txt everytime like this:step 1copy 1-8 lines from "to.txt"step 2past it over to "ftext.txt save & closestep 3 repeat now from 8-16 lines every repeat another 8 linesi know it will be the same as the original but this is how i need it Is something else meant to happen after each set of 8 lines is transfered. Do you want to have multiple files each containing 8 lines of text? I'm confused. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2010 Share Posted January 31, 2010 Array variable has incorrect number of subscripts. Local $aFileLines[9] Cheers czardas AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
voidale Posted January 31, 2010 Author Share Posted January 31, 2010 (edited) Is something else meant to happen after each set of 8 lines is transfered. Do you want to have multiple files each containing 8 lines of text? I'm confused. no just 2 txt files copy each time 8 lines from "from.txt" to "to.txt thats it Cheers czardas this one Local $Sourcefile = "from.txt" Local $destinationfile = "to.txt" Local $aFileLines[9] For $i = 1 To 8 $read = FileReadLine($Sourcefile,$i) $aFileLines[$i] = $read Next For $x=1 To 8 _FileWriteToLine($Sourcefile, 1, "", 1) Next For $i = 1 To 8 FileWriteLine($destinationfile,$aFileLines[$i]) Next gives this error, it seems _FileWriteToLine won't work to delete the lines tried to find another command to do that but nothing about it in the help file _FileWriteToLine($Sourcefile, 1, "", 1) ^ ERROR Edited January 31, 2010 by voidale Link to comment Share on other sites More sharing options...
czardas Posted January 31, 2010 Share Posted January 31, 2010 Never been hot on arraysYou are forgetting that the first element of the array is index = 0. So you should declare the array with 9 elements, not 8. Alternatively you could use an array with 8 elements and use the expression For $i = 0 To 7 etc. operator64 ArrayWorkshop 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