phatzilla Posted May 25, 2009 Share Posted May 25, 2009 So heres the problem at hand:I have a large text file with say 50 000 lines. Lets call it Mylist.txtI would like the script to take the first 500 lines or so, and create a Text file called Mylist1.txt and paste the 500 lines, create mylist2.txt with the next 500 lines, so on so forth until completion.mylist1.txt, mylist2.txt.... mylist[n].txtAnyone know if its possible to do this? How to tackle?Every bit of help is appreciated! Link to comment Share on other sites More sharing options...
Mat Posted May 25, 2009 Share Posted May 25, 2009 (edited) Is it splitting the file that you want? Then yes it is possible and there are a lot of programs to do it. Check here for a standalone and portable example.If you want it so you can read each file, then write your own!Func _SplitFile ($sFile, $sOut, $nLine = 500) Local $hFile = FileOpen ($sFile, 0) If $hFile = -1 Then Return SetError (2 + 0 * FileClose ($hFile), 0, 0) ; File Non exisstant / Hidden or system Local $x = 1, $aLines If StringInStr (FileRead ($hFile), @LF) Then $aLines = StringSplit (StringStripCR (FileRead ($hFile)), @LF) Else $aLines = StringSplit (FileRead ($hFile), @CR) EndIf FileClose ($hFile) If $nLine < 0 Then Return SetError (2, 0, 0) ; Invalid $nLine Param. For $i = 1 to $aLines[0] If Mod ($i, $nLine) = 0 Then FileClose ($hFile) $x += 1 $hFile = FileOpen ($sOut & $x & ".splt", 2) EndIf FileWrite ($hFile, $aLines[$i] & @CRLF) Next Return $x EndFunc ; ==> _SplitFileEasy enough, and reasonably paced too! I tried it on a 2000 line file, took 1 sec!Edit: Code update. (and again) Edited May 25, 2009 by mdiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
phatzilla Posted May 25, 2009 Author Share Posted May 25, 2009 (edited) I appreciate the help man, but im not too sure on how the code is supposed to work. It aint working for me. Is it supposed to spit out file1,file2.......file[n] with 500 lines each? Edited May 25, 2009 by phatzilla Link to comment Share on other sites More sharing options...
Mat Posted May 26, 2009 Share Posted May 26, 2009 (edited) Example: (run this, it will do the work. It writes the file, splits it, and writes it to seperate files. It will also bring up the folder where all this has happened afterwards)<Snip!>If You want to do your own, use_SplitFile ( "File To split" , "File template to create" , Number of lines , "Extension to use" )The file template to create is the start of the out files. If you put "...\out" you will get "...\out1.splt", "...\out2.splt" etcSplt files are basic text files, I just renamed them so you know which ones are split. If you want text files then set the "Extension to use" param to "Txt" or ".txt".MDieselEdit: Click here Edited May 26, 2009 by mdiesel AutoIt Project Listing 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