Jump to content

write to a file


Recommended Posts

$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

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

$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

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

ok so for the for/next loop where do i put the file name etc?
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...