 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
Pierre Dupuis
Joined: 22 Aug 2000 Posts: 85
|
|
FileWrite Information |
|
Hi, I have a HUGE flat file. I would like to modify only the first line of the file without recreate the file. How I can do that? Thanks.
|
|
Thu May 27, 2004 9:25 am |
|
 |
Dominic Klein
Joined: 23 Nov 2001 Posts: 132
|
|
Re: FileWrite Information |
|
: Hi, : I have a HUGE flat file. I would like : to modify only the first line of the file without : recreate the file. How I can do that? : Thanks. don't you just do fileOpen in line mode and overwrite the first line using fileWrite ? i haven't tried it but that looks like what u might have to do.
|
|
Thu May 27, 2004 9:38 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7955
|
|
Re: FileWrite Information |
|
Depending on what you want to do you can use one of the following methods: 1. Text replacing using JAL script with FileReplaceEx command 2. Text replacing using FileBinReplace command line utility (http://www.softtreetech.com/24x7/archive/50.htm) 3. Text replacing using JAL script with FileOpen( using write, stream mode and append options to open it for writing and don't truncate it), using FileSetPos to move the file pointer to the beginning of the file and then use FileWrite to write the text and FileClose at the end. This method could be tricky. 4. Partial file copying and then concatenation using FileCopy command line utility (http://www.softtreetech.com/24x7/archive/44.htm) The idea is to write a SMALL file containing the first line only, then copy your HUGE file starting with the second line into a new file and then use DOS copy command to concatenate SMALL and HUGE files together replacing old HUGE file (usage: copy SMALL + HUGE2 HUGE). 4. Call Windows API functions from a JAL script (you can use _lopen, _lread, _lwrite, _lclose or similar). This method should be very fast. To call these functions you can use JAL's Call statement. See Windows SDK documentation for more details (http://msdn.microsoft.com/library/en-us/winprog/winprog/windows_api_reference.asp). 5. Use VBScript job with a third party COM component supporting direct file read/write functions. : Hi, : I have a HUGE flat file. I would like : to modify only the first line of the file without : recreate the file. How I can do that? : Thanks.
|
|
Thu May 27, 2004 10:10 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7955
|
|
Re: FileWrite Information |
|
This will truncate the file. You need to open it with streammode and append options and then move the file read/write pointer using FileSetPos. Please see my previous post for more info. : don't you just do fileOpen in line mode and overwrite the first line using : fileWrite ? : i haven't tried it but that looks like what u might have to do.
|
|
Thu May 27, 2004 10:15 am |
|
 |
Pierre Dupuis
Joined: 22 Aug 2000 Posts: 85
|
|
Re: FileWrite Information |
|
I did a fileOpen in line mode with append to true and false. In the first case it append to end and in the second case the file is overwrite with only the fist line in it. I would like to only replace the first line. Any idea? Thanks. : don't you just do fileOpen in line mode and overwrite the first line using : fileWrite ? : i haven't tried it but that looks like what u might have to do.
|
|
Thu May 27, 2004 10:42 am |
|
 |
Pierre Dupuis
Joined: 22 Aug 2000 Posts: 85
|
|
Re: FileWrite Information |
|
I tried this without success. the FileWrite always write my line at the end of the file. // Open file in stream mode FileOpen (file_ord_targ,"StreamMode","Write",True,file_handle_ord) // Mode pointer FileSetPos file_handle_ord,1, "Start" // Re Write the header FileWrite file_handle_ord, ord_header_new FileClose file_handle_ord Any idea? Thanks. : This will truncate the file. You need to open it with streammode and append : options and then move the file read/write pointer using FileSetPos. : Please see my previous post for more info.
|
|
Thu May 27, 2004 11:21 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7955
|
|
Re: FileWrite Information |
|
Try using "START" instead of "Start" I just tested it and it works fine for me. Here is my script Dim file_handle_ord, number // Open file in stream and appemd mode FileOpen ("c:\\test.txt","StreamMode","Write",True,file_handle_ord) // Mode pointer FileSetPos file_handle_ord, 0, "START" // Re Write the header FileWrite file_handle_ord, "test2" FileClose file_handle_ord : I tried this without success. : the FileWrite always write my line at the end : of the file. : // Open file in stream mode : FileOpen : (file_ord_targ,"StreamMode","Write",True,file_handle_ord) : // Mode pointer : FileSetPos file_handle_ord,1, "Start" : // Re Write the header : FileWrite file_handle_ord, ord_header_new : FileClose file_handle_ord : Any idea? : Thanks.
|
|
Thu May 27, 2004 1:09 pm |
|
 |
Pierre Dupuis
Joined: 22 Aug 2000 Posts: 85
|
|
Re: FileWrite Information |
|
Now the fist line is overwrite with "START" but I got an error "invalid file handle or position is out of file" when I use FileSetPos file_handle_ord, 0, "START" and when I use FileSetPos file_handle_ord, 1, "START" the first digit of the file is not overwrite. Any idea? Thanks. : Try using "START" instead of "Start" : I just tested it and it works fine for me. Here is my script : Dim file_handle_ord, number : // Open file in stream and appemd mode : FileOpen : ("c:\\test.txt","StreamMode","Write",True,file_handle_ord) : // Mode pointer : FileSetPos file_handle_ord, 0, "START" : // Re Write the header : FileWrite file_handle_ord, "test2" : FileClose file_handle_ord
|
|
Thu May 27, 2004 3:05 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7955
|
|
Re: FileWrite Information |
|
I tried that with 24x7 version 3.4.17. What version are you on? : Now the fist line is overwrite with "START" but : I got an error "invalid file handle or position is out of file" : when I use FileSetPos file_handle_ord, 0, "START" : and when I use FileSetPos file_handle_ord, 1, "START" : the first digit of the file is not overwrite. : Any idea? : Thanks.
|
|
Thu May 27, 2004 3:21 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|