|
FTPEdit Scripting
Insert a new top-level menu and a menu item
The following code will insert a new top-level menu item called Execute and then a menu-item underneath it called Perl. Clicking on the Perl menu item will look for a procedure named OnExecutePerl and call it. Clear dim newSubMenu dim newMenuItem set newSubMenu = Menu.Insert(7, "E&xecute", "", TRUE) newSubMenu.Hint = "Execute external programs" set newMenuItem = newSubMenu.Insert(0, "Perl", "OnExecutePerl", FALSE) newMenuItem.Hint = "Execute Perl interpreter on active file" newMenuItem.Shortcut = "F8"
Execute an external program
Attach this script to a menu item using the above code. It will save the current file and execute the Perl interpreter on it. sub OnExecutePerl
Clear
with ActiveFile
' Verify that the file resides locally
' Enhancement idea: if remote file, save to a local
' directory temporarily and then execute it
if not IsLocal then
print "Can't execute Perl on a remote file."
exit sub
end if
' Save the file if it has been modified
if .Modified then
if not .Save then
' If the file did not save for some reason, don't execute Perl
exit sub
end if
end if
print "Executing Perl interpreter on " + .Filename + "..."
dim sOutput
exec "perl -w " + .Filename, .Directory, sOutput
' Print the output to the screen
print sOutput
end with
end sub
How to include files
Place to following procedure in your Startup.vbs file to give you global access to it. ' Define an easy way of including files. sub include (sNameScript) Set oFS = CreateObject("Scripting.FileSystemObject") Set oFile = localAccount.openFileForReading(cNameScript, true) ExecuteGlobal oFile.ReadAll() set oFile = nothing end sub
How to read and write to files
You can access files using the openFileForReading and openFileForWriting procedures accesible through an account. Clear print "Opening file for reading" set oFile = localAccount.OpenFileForReading("C:\test.txt", true) print "Saving file remotely" ' Save to the remote account named "test account" ' You can also access Accounts() numerically to iterate through ' the available accounts accounts("test account").openFileForWriting "/test.txt", oFile, true set oFile = nothing |