Thread: VBS to Python
View Single Post
Old 06-05-2021, 11:23 AM
gregg gregg is offline
Registered User
Join Date: Oct 2010
Posts: 75
This should be an adequate replacement for the mentioned script.

# $language = "Python3"
# $interface = "1.0"

# Script to open a text file and read it line by
# line to a server.

DEFAULT_FILENAME = r"F:\SecureCRT\sqlScripts\DBA_Feature_usage.sql"

def main():
    # filename = crt.Dialog.Prompt("Filename to read:", "Filename", DEFAULT_FILENAME, False)
    filename = crt.Dialog.FileOpenDialog("Text file", "Open", DEFAULT_FILENAME, "SQL Files (*.sql)|*.sql|All Files (*.*)|*.*|")

    if not filename:
        # escape pressed or no filename entered

    crt.Screen.Synchronous = True
        # Open a file for reading.
        with open(filename, "rt") as fh:
            for line in fh:
                crt.Screen.Send(line.rstrip() + "\r")
    except FileNotFoundError:
        crt.Dialog.MessageBox("Could not open file %s" % filename, "File not found")
        crt.Screen.Synchronous = False
Reply With Quote