Thursday, November 19, 2009

KiXtart: Using FSO File.ReadAll()

Another example of making use of one scripting language or API from another.  In this case, I’m calling on the FileSystemObject API to invoke the ReadAll() function on a file from a KiXtart script.  Just to show that there are all sorts of things you can do like this…

function ReadFile($filepath)
$fso = CreateObject("Scripting.FileSystemObject")
if exist($filepath)
$file = $fso.OpenTextFile($filepath)
$text = $file.ReadAll()
$file.Close()
$file = 0
else
? "error: file not found"
endif
$readfile = $text
endfunction

; example...

? readfile("c:\myfile.txt")

No comments:

Post a Comment