afsar Posted September 2, 2005 Share Posted September 2, 2005 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 Link to comment Share on other sites More sharing options...
MHz Posted September 2, 2005 Share Posted September 2, 2005 Are you using the filehandle return by FileOpen within the FileWrite function? Link to comment Share on other sites More sharing options...
afsar Posted September 2, 2005 Author Share Posted September 2, 2005 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 Link to comment Share on other sites More sharing options...
MHz Posted September 2, 2005 Share Posted September 2, 2005 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') Link to comment Share on other sites More sharing options...
afsar Posted September 7, 2005 Author Share Posted September 7, 2005 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 EndFuncThen 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 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