cypher175 Posted July 24, 2009 Posted July 24, 2009 ello govena.. I need to open a .txt file then delete the top 4 lines in it, then save it as a new "file.(1).txt" and so on in a loop.. so each new file is like "file.(1).txt" , "file.(2).txt" , "file.(3).txt" , "file.(4).txt" Ect.. each with 4 lines removed from the previous "file.(#).txt" how exactly could i do this..??
z0mgItsJohn Posted July 24, 2009 Posted July 24, 2009 This does not loop.. but it will get you started. Code : #Include <File.Au3> $File = 'Test.txt' $FileType = '.txt' $CharCount = StringSplit ($FileType, '') $NewName = StringTrimRight ($File, $CharCount[0]) & '(1)' & $FileType For $A = 5 To _FileCountLines ($File); this makes it so it discludes lines 1-4 $Read = FileReadLine ($File, $A) FileWriteLine ($NewName, $Read) Next Hope it helps! - John Latest Projects :- New & Improved TCP Chat
Malkey Posted July 24, 2009 Posted July 24, 2009 ello govena.. I need to open a .txt file then delete the top 4 lines in it, then save it as a new "file.(1).txt" and so on in a loop.. so each new file is like "file.(1).txt" , "file.(2).txt" , "file.(3).txt" , "file.(4).txt" Ect.. each with 4 lines removed from the previous "file.(#).txt" how exactly could i do this..?? Like this. NOTE: This script will save a number of files named "test.(Number).txt" to your script's directory. ; Local $sFileIn = @ScriptDir & "\test.txt" Local $1TotLines, $sStr, $aFile, $hFile, $sNewPath_Name, $iFileNum = 1 If FileExists($sFileIn) = 0 Then Exit Local $filtxt = FileRead($sFileIn) While 1 $aFile = StringRegExp($filtxt, ".+(?=\v+|$)", 3) ; returns array of every line $1TotLines = UBound($aFile) ; Total number of lines If $1TotLines > 4 Then $sStr = StringRegExpReplace($filtxt, "(.*\v+){4}(?s)(.*)", "\2") $sNewPath_Name = StringRegExpReplace($sFileIn, "(^.*)\.(.*)", "\1") & ".(" & $iFileNum & ")" & StringRegExpReplace($sFileIn, "^.*\.", ".$1") $hFile = FileOpen($sNewPath_Name, 10) FileWrite($hFile, $sStr) FileClose($hFile) ;ConsoleWrite($1TotLines & @CRLF &$sStr & @CRLF & @CRLF) $filtxt = $sStr $iFileNum += 1 Else ExitLoop EndIf ;ShellExecute($sNewPath_Name) ; Opens file with the application associated with the file extension. WEnd ;
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