From: mayayana on
Todd Vargo's point is something I hadn't thought
of: Even if you can replace bytes in the file, you
can't change the length without dealing with the
whole thing. If there were any chance of just writing
the new bytes you'd need to have extra spaces
following the number to accomodate that.

To me that all seems like the wrong question,
though. The real question is why you're creating
files in the first place that are so big as to be
unwieldy to work with.




From: Todd Vargo on
francois wrote:
> Todd Vargo a �crit :
>
>> I'm sure there is a *simple* way, but unfortunately, your first post did
>> not mention if you will always be replacing the characters with the same
>> number of other characters, if the characters to be replaced are in a
>> fixed location within file, or even what OS this will be used on.
>
> Sorry for my lack of precision, I didn't think that was important.
>
> The replacement is always located in the firt line of the text file. The
> firt line is always of this form :
>
> ------------------------------------
> number: 2345
> ------------------------------------
>
> where :
>
> - "number: " is a label which never changes.
> - "2345" is a number which changes. In fact, the number increases. So,
> the number of characters can change, it's possible to have "12044". But
> this number represents the number of printed pages by a user. So, it's
> almost sure that the necessary number of characters will be lower than 20
> (for example).
>
> The script should work sometimes in Windows 2000 server and sometimes in
> Windows XP pro.
>
> I hope this time, my precisions are enough. :-)

Do you know for sure that the number will fill the spaces to the left? If
the line grows to the right then there is no way to accomplish this.
However, if you are replacing the 4 digit number with a lower number on a
regular basis, then maybe it will never reach 5 digits. Replacing the
characters is simple if you are interested in a qbasic/gwbasic solution.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

From: Todd Vargo on

"mayayana" <mayayana(a)nospam.invalid> wrote in message
news:%23UCG94CsKHA.5568(a)TK2MSFTNGP05.phx.gbl...
>> Mayayana wrote the code of a class which allows to manage binary files.
> Maybe you could
>> read/write the single bytes you need.
>> I think it's not worth the effort.
>>
>> The TS Bin class is here
>> http://www.jsware.net/jsware/scripts.php5#codelib
>>
>
> That's handy for treating fiiles as binary, but it's
> still using FSO, so it has to read out the whole file.
> I also wrote a component that's more efficient.
> I haven't looked at that code for awhile. I
> think it will write bytes to a file without needing
> to load the file. But it uses basic VB methods like
> Seek, Put, etc. I'm not certain that the file is not
> loaded "behind the scenes" with those methods.
>
> http://www.jsware.net/jsware/scripts.php5#jsbin

jsbin.dll was kind of a pain to figure out, but the following vbscript will
do what the OP wants using it.

'Note, jsbin.dll must be registered before use.
'Read "JSBin README.txt" for instructions.

Dim FSO, bin, e, s, L
Set FSO = CreateObject("Scripting.FileSystemObject")
Set bin = CreateObject("JSBin.BinaryOps")

'--create or open the file to write:
e = bin.BinaryOpen("test2.txt", 0)
If e <> 0 Then
msgbox "Error opening or creating file. Error number: " & e
wscript.Quit
End If

'number: 2345'
s = "number: 0000" 'Put new text here
ReDim A(Len(s) - 1)
For i = 1 To Len(s)
A(i - 1) = Asc(Mid(s, i, 1))
Next

'--write the bytes, starting from 0 as byte 1:
e = bin.BinaryWrite(A, 0)

'--close file (required):
e = bin.BinaryClose

Set bin = Nothing

MsgBox "Done."


--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

From: mayayana on

>
> I'm sure that the necessary number of characters to write
> the number ("72", "102", "44507" etc.) will be lower than
> 20. Is it possible to do this with vbscript without reading
> and memorizing the rest of the text file ? The question
> interests me for itself.
>

That seems doable. So you just need to write
the first 20 bytes/characters, regardless of the number
you need to write.You can't do it with
Textestream/VBScript but probably with AutoIt,
JSBin, or something similar. You'd need to test it.
I think that a file can be opened and bytes written
without loading the whole thing. I think JSBin
works that way. But I'm not certain.

> I hope it's clear this time. :-)
>

It's still not clear to me why anyone would write
files that are too big to handle, but that's really
your decision.



From: Todd Vargo on
francois wrote:
> mayayana wrote :
>> To me that all seems like the wrong question,
>> though. The real question is why you're creating
>> files in the first place that are so big as to be
>> unwieldy to work with.
>
> Ok, I understand. I wanted to be simple and precise in my post (I failed,
> I apologize but I'm French and it's hard for me to be talkative in my
> post, It takes me a lot of time to write the least message). So, I'm going
> to tell you.

What is the largest file size you need to modify? Perhaps you are being
overly concerned about reading the entire file into memory.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)