#80760 - 2002-04-19 01:00 AM
OPEN an existing file with possibility to overwrite all data in file
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
Currently you must first delete an existing file to make it possible to rewrite this file with WRITELINE statements.
We will suggest that the OPEN will extend we a new "mode":
- 0 = if the file does not exist, OPEN failswith return code 2 (default)
- 1 = if the file does not exist, OPEN will create a new file
- 2 = opens the file for rad access(default)
- 4 = opens the file for write access
- 8 = opens the file for write access and all previous data in file will
overwritten (new) or we will suggest the introducing of new REWRITELINE function, which will have same format as WRITELINE but will overwrite all previous infor- mation on that file.
greetings.
btw: "RedirectOutput" has such "overwrite" option.
|
|
Top
|
|
|
|
#80763 - 2002-05-02 07:33 PM
Re: OPEN an existing file with possibility to overwrite all data in file
|
Anonymous
Anonymous
Unregistered
|
I just want to simply add my support for this request!
Yes Please!
Lee
|
|
Top
|
|
|
|
#80764 - 2002-05-02 09:01 PM
Re: OPEN an existing file with possibility to overwrite all data in file
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
perhaps a function to write to a specific line
Writeline () BOF line xx EOF
|
|
Top
|
|
|
|
#80765 - 2002-05-02 09:12 PM
Re: OPEN an existing file with possibility to overwrite all data in file
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I have a UDF that does this if anyone wants it. I was going to post it in the UDF libary but there was already an OpenFile() posted. code:
;FUNCTION OpenFile() ; ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ; ;ACTION Opens file based on specified parameters. Supports overwriting a file. ; ;SYNTAX OpenFile(FileName, R|W, [0|1], [0|1]) ; ;PARAMETERS $FileName (Required) - String value ; $ReadWrite (Required) - String value ; $Create (Optional) Default(0) Do not create a new file. (1 or 0) ; $OverWrite (Optional) - Default(0) Append (1 or 0) ; ; ;REMARKS This function attempts to open the specified file. @error is set on exit. ; The UDF will search for the first available file number. ; ;RETURNS File handle (integer 1-10) if successful; nothing if error ; ;DEPENDENCIES None ; ;EXAMPLES $FH = OpenFile("junk.txt", "W") ;Open file for write; do not create the file; append ; if @error = 0 ; Writeline($FH, "Some text") ; endif ; ; $FH2 = OpenFile("junk2.txt", "W", 1, 1) ;Open file for write; create the file; delete old file ; if @error = 0 ; Writeline($FH2, "Some text") ; endif; ; Function OpenFile($FileName, $ReadWrite, optional $Create, optional $Overwrite) Dim $FileName, $ReadWrite, $Create, $Overwrite Dim $FH, $RC, $Mode
; Validate input parameters if VarType($Create) = 0 $Create = 0 endif if VarType($Overwrite) = 0 $Overwrite = 0 endif if not (VarType($FileName) = 8 and ($ReadWrite = "R" or $ReadWrite = "W") and ($Create = 0 or $Create = 1) and ($Overwrite = 0 or $Overwrite = 1) ) ;WriteLog($LogFile, "OpenFile: Error in parameters (" + $FileName + ", " + $ReadWrite + ", " + $Create + ", " + $OverWrite + ")") exit 1 endif if $Create < $OverWrite ;WriteLog($LogFile, "OpenFile: Error in parameters ("You must specify Create=1 when OverWrite=1") exit 1 endif
; Build Mode value if $Create = 0 $Mode = 0 else $Mode = 1 endif if $ReadWrite = "R" $Mode = $Mode + 2 else $Mode = $Mode + 4 endif
;Handle OverWrite option if $OverWrite = 1 if exist ($Filename) del $Filename endif endif
; Open file $FH=1 $RC=Open ($FH, $FileName, $Mode) ? "@error @serror" if $RC <> 0 select case $RC=2 ;WriteLog("open($FileNum, $FileName, $Mode) Error: $RC (Cannot find the file specified)") exit $RC case $RC=-3 while $RC = -3 and $FH < 11 $RC=Open ($FH, $FileName, $Mode) if $RC = -3 $FH=$FH +1 endif Loop if $RC = -3 ;WriteLog("open($FileNum, $FileName, $Mode) Error: $RC (All file numbers are in use.)") exit $RC endif case $RC=-2 ;WriteLog("open($FileNum, $FileName, $Mode) Error: $RC (Invalid file number specified)") exit $RC case $RC=-1 ;WriteLog("open($FileNum, $FileName, $Mode) Error: $RC (File number already in use)") exit $RC case 1 ;WriteLog("open($FileNum, $FileName, $Mode) Error: $RC (System error)") exit $RC endselect endif ;WriteLog("Success: Open($FileNum, $FileName, $ReadWrite, $OverWrite) returned file handle: ") $OpenFile = $FH exit 0 Endfunction
|
|
Top
|
|
|
|
#80766 - 2002-05-20 11:52 PM
Re: OPEN an existing file with possibility to overwrite all data in file
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear Howard,
Indeed the UDF is a good suggestion, but in the past there are big problems with the way is handling file actions. Simply overwrite specifies file will work for all windows versions. See our topic http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=3;t=000014 which handles about "timing problems flushing output and setting attributes". greetings.
|
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 1110 anonymous users online.
|
|
|