How can I read files in my script?

CRT™ 3.0/SecureCRT® 3.0 does not offer direct support for reading and writing to files, but the ActiveX scripting language you are

Microsoft's VBScript and JScript languages both allow you to create instances of "filesystem objects" that offer a flexible interface for manipulating files.

The following VBScript sample code creates a filesystem object, opens a file then reads the file line by line and sends it to a server:

# $language = "VBScript"
# $interface = "1.0"

Sub main

' Open a file, read it in & send it one line at a time
Dim fso, f, str
Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\temp\file.txt", ForReading, 0)

Do While f.AtEndOfStream <> True
     str = f.Readline
     crt.Screen.Send str & Chr(13)
     ' Wait for my prompt before sending another line

End Sub

The following JScript sample code performs a similar operation:

# $language = "JScript"
# $interface = "1.0"

function main()
        var fso, f;
        var ForReading = 1, ForWriting = 2;

         fso = new ActiveXObject("Scripting.FileSystemObject");
         f = fso.OpenTextFile("c:\\temp\\file.txt", ForReading);

         while ( f.AtEndOfStream != true )
             var str = f.Readline();

             // Append a CR to the line (decimal: 13, octal: 15).
             str += "\015";

             crt.Screen.Send( str );

Was this information helpful?
Yes No

Thank you!
Send your comments and questions to VanDyke Software Support,
or join the discussion in the VanDyke Software Forums.

Can't find the answer you're looking for?
Ask VanDyke Software Support directly
and we will get back to you as soon as possible.


VanDyke Software uses cookies to give you the best online experience. Before continuing to use this site, please confirm that you agree to our use of cookies. Please see our Cookie Usage for details.