jannlee300 Posted March 29, 2009 Share Posted March 29, 2009 how do i write a "0" to the first 9 lines of a file Link to comment Share on other sites More sharing options...
Valuater Posted March 29, 2009 Share Posted March 29, 2009 I am guessing you might be interested in... IniWrite() IniRead() If so, See the help file for examples 8) Link to comment Share on other sites More sharing options...
Authenticity Posted March 29, 2009 Share Posted March 29, 2009 $sFile = @ScriptDir & '\MyTest.txt' $sText = FileRead($sFile) $hFile = FileOpen($sFile, 2) FileWrite($hFile, StringRegExpReplace($sText, '\r\n', '0'&@CRLF, 9)) FileClose($hFile) #cs #### MyTest.txt content: #### #### MyTest.txt content (modified): #### 1 10 2 20 3 30 4 40 5 50 6 60 7 70 8 80 9 90 10 10 11 11 12 12 13 13 14 14 15 15 #ce Not a good idea for big files, if applicable. Link to comment Share on other sites More sharing options...
maqleod Posted March 29, 2009 Share Posted March 29, 2009 alternatively, filewriteline() with a for/next loop would also work, and would be the simplest, but would only work if you needed to write the first 9 lines in order and didn't have to edit specific lines, otherwise the ini functions would be best [u]You can download my projects at:[/u] Pulsar Software Link to comment Share on other sites More sharing options...
jannlee300 Posted March 29, 2009 Author Share Posted March 29, 2009 $sFile = @ScriptDir & '\MyTest.txt' $sText = FileRead($sFile) $hFile = FileOpen($sFile, 2) FileWrite($hFile, StringRegExpReplace($sText, '\r\n', '0'&@CRLF, 9)) FileClose($hFile) #cs #### MyTest.txt content: #### #### MyTest.txt content (modified): #### 1 10 2 20 3 30 4 40 5 50 6 60 7 70 8 80 9 90 10 10 11 11 12 12 13 13 14 14 15 15 #ce Not a good idea for big files, if applicable.ok thanks but i dont want to add a 0 i want to over write say a 20 to a 0 Link to comment Share on other sites More sharing options...
jannlee300 Posted March 29, 2009 Author Share Posted March 29, 2009 alternatively, filewriteline() with a for/next loop would also work, and would be the simplest, but would only work if you needed to write the first 9 lines in order and didn't have to edit specific lines, otherwise the ini functions would be bestok so for the for/next loop where do i put the file name etc? Link to comment Share on other sites More sharing options...
Authenticity Posted March 29, 2009 Share Posted March 29, 2009 To replace the first 9 lines with '0': $sFile = @ScriptDir & '\MyTest.txt' $sText = FileRead($sFile) $hFile = FileOpen($sFile, 2) FileWrite($hFile, StringRegExpReplace($sText, '.*\r\n', '0'&@CRLF, 9)) ; '0' FileClose($hFile)oÝ÷ Ù:+zZqëayø«²ßew¬Â+aßÝýaxºÚ"µÍÌÍÜÑ[HHØÜ [È ÌÎNÉÌLÓ^UÝ ÌÎNÂÌÍÜÕ^H[TXY ÌÍÜÑ[JBÌÍÚ[HH[SÜ[ ÌÍÜÑ[KB[UÜ]J ÌÍÚ[KÝ[ÔYÑ^XÙJ ÌÍÜÕ^ ÌÎNËÌLÜÌLÛÌÎNË ÌÎNÉÌÎNËJJHÈÝ[Â[PÛÜÙJ ÌÍÚ[JoÝ÷ ÙK"¢³^ÆÙh¢®¶sb6æ6ÇVFRfÇC´fÆRæS2fwC° ¤FÒb33c·4fÆRÒ67&DF"fײb33²b3#´×FW7BçGBb33²Âb33c¶ÆæW0¥ôfÆU&VEFô'&b33c·4fÆRÂb33c¶ÆæW2 ¤f÷"b33c¶ÒFò b33c¶ÆæW5²b33c¶ÒÒb33³b33°¤æW@ ¥ôfÆUw&FTg&öÔ'&b33c·4fÆRÂb33c¶ÆæW2 Link to comment Share on other sites More sharing options...
maqleod Posted March 29, 2009 Share Posted March 29, 2009 ok so for the for/next loop where do i put the file name etc? this would require that you have an array setup with the contents, so it may not be ideal for you, but if it is, this is how it would work: For $i = 1 to 9 FileWriteLine("yourfilename.txt",$linecontents[$i]) Next [u]You can download my projects at:[/u] Pulsar Software Link to comment Share on other sites More sharing options...
jannlee300 Posted March 29, 2009 Author Share Posted March 29, 2009 To replace the first 9 lines with '0': $sFile = @ScriptDir & '\MyTest.txt' $sText = FileRead($sFile) $hFile = FileOpen($sFile, 2) FileWrite($hFile, StringRegExpReplace($sText, '.*\r\n', '0'&@CRLF, 9)) ; '0' FileClose($hFile)oÝ÷ Ù:+zZqëayø«²ßew¬Â+aßÝýaxºÚ"µÍÌÍÜÑ[HHØÜ [È ÌÎNÉÌLÓ^UÝ ÌÎNÂÌÍÜÕ^H[TXY ÌÍÜÑ[JBÌÍÚ[HH[SÜ[ ÌÍÜÑ[KB[UÜ]J ÌÍÚ[KÝ[ÔYÑ^XÙJ ÌÍÜÕ^ ÌÎNËÌLÜÌLÛÌÎNË ÌÎNÉÌÎNËJJHÈÝ[Â[PÛÜÙJ ÌÍÚ[JoÝ÷ ÙK"¢³^ÆÙh¢®¶sb6æ6ÇVFRfÇC´fÆRæS2fwC° ¤FÒb33c·4fÆRÒ67&DF"fײb33²b3#´×FW7BçGBb33²Âb33c¶ÆæW0¥ôfÆU&VEFô'&b33c·4fÆRÂb33c¶ÆæW2 ¤f÷"b33c¶ÒFò b33c¶ÆæW5²b33c¶ÒÒb33³b33°¤æW@ ¥ôfÆUw&FTg&öÔ'&b33c·4fÆRÂb33c¶ÆæW2Âthanks for all your help 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