Jump to content
Sign in to follow this  
afsar

File write

Recommended Posts

afsar

hi,

i want to write in a text file which erases previous contents and writes new line everytime..

i opend the file with fileopen($file,2) ( erase prevoius contents mode)

when i use filewrite or filewriteline it is appending to that..

thanx

Afsar

Share this post


Link to post
Share on other sites
MHz

Are you using the filehandle return by FileOpen within the FileWrite function?

Share this post


Link to post
Share on other sites
afsar

Are you using the filehandle return by FileOpen within the FileWrite function?

<{POST_SNAPBACK}>

actually my problem is

$fi = fileopen($file,2)

filewrite($fi,"1st line")

filewrite($fi,"2nd line")

and my final output is:

2nd line..

this i want

Share this post


Link to post
Share on other sites
MHz

Here is a simple User Defined Function which should do as what you want?

Add this function to you script, normally at the bottom.

Func _Write($file, $line)
    Local $handle = FileOpen($file, 2)
    If $handle <> -1 Then
        FileWrite($handle, $line)
        FileClose($handle)
    EndIf
EndFunc

Then in that script, just call the function with the parameters filled in like:

_Write('C:\file.txt', 'Text is put here')

Share this post


Link to post
Share on other sites
afsar

Here is a simple User Defined Function which should do as what you want?

Add this function to you script, normally at the bottom.

Func _Write($file, $line)
    Local $handle = FileOpen($file, 2)
    If $handle <> -1 Then
        FileWrite($handle, $line)
        FileClose($handle)
    EndIf
EndFunc

Then in that script, just call the function with the parameters filled in like:

_Write('C:\file.txt', 'Text is put here')

<{POST_SNAPBACK}>

thanx works perfect.......

Afsar

Share this post


Link to post
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
Sign in to follow this  

×