From: francois on 12 Feb 2010 19:14 Hi everybody, I have a text file called "Mytext.txt" like this: ------------------------- number: 2345 some text blabla.... some text blabla.... some text blabla.... some text blabla.... some text blabla.... some text blabla.... some text blabla.... some text blabla.... ------------------------- I just would like modify the number in the firt line (2345), without put in the memory the rest of the text or create a new temporay file? Is it possible? I ask this question because I want to use this script with lot of text files and this text files are quite big. Thanks in advance. -- Fran�ois Lafont
From: mr_unreliable on 16 Feb 2010 11:20 francois wrote: > I just would like modify the number in the firt line (2345), without put > in the memory the rest of the text or create a new temporay file? Is it > possible? > Bonjour Francois, As best I can tell, you are not going to be able to do this with vbScript. If you have a vb compiler handy, it may be worth your while to learn/use vb -- more specifically the "binary" read write capability, the "Get" and "Put" commands. There are also other scripting languages with binary read/write capabilities (most of them free) which will work. When considering some other scripting language, look for "file open as binary" in the help file, or the feature listing. cheers, jw ____________________________________________________________ You got questions? WE GOT ANSWERS!!! ..(but, no guarantee the answers will be applicable to the questions)
From: Todd Vargo on 16 Feb 2010 16:08 mr_unreliable wrote: > francois wrote: >> I just would like modify the number in the firt line (2345), without put >> in the memory the rest of the text or create a new temporay file? Is it >> possible? >> > > Bonjour Francois, > > As best I can tell, you are not going to be able to > do this with vbScript. > > If you have a vb compiler handy, it may be worth your > while to learn/use vb -- more specifically the "binary" > read write capability, the "Get" and "Put" commands. > > There are also other scripting languages with binary > read/write capabilities (most of them free) which > will work. When considering some other scripting > language, look for "file open as binary" in the > help file, or the feature listing. That has always annoyed me about vbscript. GWbasic/Qbasic supports binary mode, but I guess they wont be useful to many Win7 users. One caveat to OP though. Changing 2345 to some other 4 characters wont be a problem when using binary mode. However, changing the number of characters will require reading and rewriting the entire file. -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages)
From: mr_unreliable on 16 Feb 2010 17:36 Todd Vargo wrote: > GWbasic/Qbasic supports binary mode, but I guess > they wont be useful to many Win7 users. > fwiw, I suggest QBasic lovers take a look at FreeBasic: http://www.freebasic.net/ It appears to have begun as a QBasic replacement, but was then expanded and enhanced from there. It currently appears to be actively supported, and has an active user forum. There also appears to be a little "cross-fertilization" going on, i.e., people are taking PowerBasic (costing $200) code, and converting it to FreeBasic (free). The point of mentioning this is that while freebasic is not as powerful as PowerBasic, it comes close. (pause to wait for vociferous dissent... ). cheers, jw
From: Reventlov on 17 Feb 2010 16:44 Il giorno Sat, 13 Feb 2010 01:14:49 +0100, francois <francois(a)NoSpam.fr> ha scritto: >I just would like modify the number in the firt line (2345), >without put in the memory the rest of the text or create a >new temporay file? Is it possible? > >I ask this question because I want to use this script with >lot of text files and this text files are quite big. 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 And this is the header ' Reading info from binary files: ' ' GetSize(FilePath) - returns size of file in bytes. ' ' Read(FilePath, Start, Length) - returns a string from file. ' ' GetArray(StringIn, SnipUnicode) - convert a string to an array of byte values. If SnipUnicode = True then get only every 2nd byte. ' ' GetByteString(StringIn, KeepZeros, SnipUnicode) - convert a string to a manageable version. ' If KeepZeros = True then 0-bytes are converted to * ' If SnipUnicode = True then get only every 2nd byte. ' ' GetNumFrom4Bytes(array(3)) - takes array of ubound 3. return numeric value for 4 bytes. ' ' GetNumFrom2Bytes(array(1)) - takes array of ubound 1. return numeric value For 2 bytes. ' ' Writing binary files: ' ' WriteFileA(sFilePath, ArrayIn, OverWrite) Write a file with an array of numeric byte values (0 to 255). ' ' AppendFileA(sFilePath, ArrayIn) append to a file With an array of numeric byte values (0 to 255). ' ' WriteFileS(sFilePath, StringIn, OverWrite) - Write file with string. ' ' AppendFileS(sFilePath, StringIn) - append to file with string. ' ' ' ConvertToBase64(sBytes, AddReturns) - convert bytes to Base 64. Takes byte string and returns Base 64 text. ' ' DecodeBase64(Str64) - convert Base 64 to bytes. Takes Base 64 text string and returns byte string. -- Giovanni Cenati (Bergamo, Italy) Write to "Reventlov" at katamail com http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) --
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: unable to update HTA with WMI data. Next: Script to Run System Backup in Vista |