[jawsscripts] Fw: writing and reading from text files, by Jamal

  • From: "Paul Magill" <magills@xxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Sun, 7 Jun 2009 12:29:47 +1000

Hi,

below is a post by Jamal, detailing how to write & read directly from text 
files.

I use these functions extensively in my scripting, & appreciate Jamal making 
them available to us.

I would suggest using the function FileExists, to check the existance of a 
file, before trying to read from it, & to check that a folder exists before 
trying to write a file to it.


----- Original Message ----- 
From: "Jamal Mazrui" <Jamal.Mazrui@xxxxxxx>
To: <Jawsscripts@xxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, March 22, 2006 4:20 AM
Subject: RE: writing and reading from text file


Below are the functions ObjectCreate, FileToString, and StringToFile.
ObjectCreate is a support function for the the other two.  FileToString
creates a text file from a string.  StringToFile Returns the contents of
a text file as a string.  These functions use the object model of the
Windows Script Host.

Hope this helps,
Jamal

Object Function ObjectCreate(String s_object)
Var
Object o_return

Let o_return =CreateObjectEx(s_object, True)
If !o_return Then
Let o_return =CreateObjectEx(s_object, False)
EndIf
If !o_return Then
Let o_return =GetObject(s_object)
EndIf
Return o_return
EndFunction

String Function FileToString(String s_file)
Var
Object Null,
Object o_system,
Object o_file,
String s_return

Let o_system =ObjectCreate("Scripting.FilesystemObject")
Let o_file =o_system.OpenTextFile(s_file, 1, 0)
Let s_return =o_file.ReadAll()
o_file.close()
Let o_file =Null
Let o_system =Null
Return s_return
EndFunction

Int Function StringToFile(String s_text, String s_file)
Var
Object Null,
Object o_system,
Object o_file

Let o_system =ObjectCreate("Scripting.FilesystemObject")
Let o_file =o_system.CreateTextFile(s_file, 1, 0)
o_file.write(s_text)
o_file.close()
Let o_file =Null
Let o_system =Null
EndFunction


__________ 
Visit and contribute to The JAWS Script Repository http://jawsscripts.com

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts:

  • » [jawsscripts] Fw: writing and reading from text files, by Jamal - Paul Magill