Re: Writing to a file and then reading the file contents by Steven
Steven
Sat Feb 18 15:59:47 CST 2006
You can substitute and use "COM1:" by issuing a Replace command to remove
the :, prior to creating the file....
'// Replace : with a .txt extension
sFile = Replace("COM1:", ":", ".txt")
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(sFile,True)
> What I need is to open or create a file
> and write to it and then read from it with out using a second
> "open" evolution. It needs to either be opened or created, then
> write and read while open, then close it.
You can't do that .... the content of the buffer isn't in the buffer until
it's opened (and it can't be placed into the buffer without opening it). If
you need simply to get it's content, write the output to a var - then save
the var, and use the var to read...
i.e.
Dim sOutput
sOutput = [whatever]
'// <save to file>
'// read var
WScript.Echo sOutput
--
Regards
Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk
Keeping it FREE!
"Si Ballenger" <shb*NO*SPAM*@comporium.net> wrote in message
news:43f79249.16138085@news.comporium.net...
> What you put won't work substituting "com1:" in place of the
> "test.txt". You appear to make the file, then "open" it a second
> time to get the contents. What I need is to open or create a file
> and write to it and then read from it with out using a second
> "open" evolution. It needs to either be opened or created, then
> write and read while open, then close it.
>
> On Sat, 18 Feb 2006 21:03:10 -0000, "Steven Burn"
> <somewhere@in-time.invalid> wrote:
>
> >You really need to improve your naming conventions .... and yes, it can.
> >
> >*********************************
> >Option Explicit
> >Dim objFSO, objFile, sFile
> >sFile = "test.txt"
> >Set objFSO=CreateObject("Scripting.FileSystemObject")
> >Set objFile = objFSO.CreateTextFile(sFile,True)
> >objFile.write "this is a test"
> >Wscript.Sleep 1000
> >'// get test.txt file contents here
> >Set objFile = objFSO.OpenTextFile(sFile)
> >'// wscript.echo test.txt file contents here
> >WScript.Echo objFile.ReadAll
> >objFile.Close: Set objFSO = Nothing: Set objFile = Nothing
> >*********************************
> >
> >--
> >Regards
> >
> >Steven Burn
> >Ur I.T. Mate Group
> >www.it-mate.co.uk
> >
> >Keeping it FREE!
> >
> >"Si Ballenger" <shb*NO*SPAM*@comporium.net> wrote in message
> >news:43f7798b.9812028@news.comporium.net...
> >> How does one write to a file and then read the file contents with
> >> out closing the file inbetween (if it is possible)? I'm tinkering
> >> with the serial com port to see if the input buffer can be read
> >> after writing to the output buffer. I can write bytes and such to
> >> the comport by treating it like a file (substitute "COM1:" for
> >> the "test.txt"), so the next question is can I get the contents
> >> of the input buffer by reading the open file before closing it.
> >> Can the below code be fixed such that it can read the contents of
> >> the test.txt file after writing to it with out closing the file
> >> first?
> >>
> >> ===================
> >>
> >> Set fs=CreateObject("Scripting.FileSystemObject")
> >> Set a = fs.CreateTextFile("test.txt",True)
> >>
> >> a.write "this is a test"
> >>
> >> Wscript.Sleep 1000
> >>
> >> 'get test.txt file contents here
> >>
> >> 'wscript.echo test.txt file contents here
> >>
> >> a.Close()
> >>
> >
> >
>