Scripts and Automation: File Selection from a scriptA small example script that uses VBScript and the ScriptDlg DLL to create a file selection drop-list.
This script illustrates using the File System Object to select files. This could be used for choosing a test to run (as is done here) or for selecting a file of information (such as microphone calibration data). The basic concept is that we set up a user interface with ScriptDlg which incorporates a drop-list. This lists all the files in a particular folder of a particular type plus a button to open or execute the selected file. The description that follows assumes some knowledge of the basics of VB Script and is only concerned with the use of the File System Object to list files in a folder.
The File System Object
The File System Object (FSO) object model allows you to use the "object.method" syntax with a rich set of properties, methods, and events to process folders and files. It is primarily intended for use with developing web sites using server side scripting, but is accessible from the Windows Scripting Host using VBS and dScope DSS scripts.
To access it, we need to create the object using the line:
Set FSO = CreateObject("Scripting.FileSystemObject")
We now have access to the file system object's methods and properties which we can use to gain access to the folders and files on the computer. The next step in the example given here is to list all the files in a particular folder. We do this by:
Set strFolder = FSO.GetFolder(strpath) ' Loop through files, adding those with dss extension to the drop-list For Each strFile in strFolder.files strName = strFile.Name If (right(strName, 3) = "dss") then strName = left(strname, (len(strname)-4)) selector.TestSel.AddString strName End If Next 'Select the first test so as not to leave the box blank selector.TestSel.cursel = 0
There is quite a bit in the above code that is out of the scope of the discussion here, but the pertinent lines are the first line, which sets the folder we are working with as an object in its own right, and the line beginning "For Each" which gets each file in the defined folder. The remaining lines in the For-Next loop retrieve the name of the file, check whether the last three characters are "dss", and add them to the drop-list of tests if they do. The last line simply selects the first file as the one to display in the drop-list so that the drop-list is not empty.
Download the script and unzip it to the dScope /scripts/automation folder. You can run it from the "automation/run script" menu option or from the "run script" button on the toolbar.
Because it is a script, you can open it to copy and paste relevant parts, or modify it to do what you want. To run it, simply select it from the "run script" dialogue in the dScope software. It is set in the script to look for the dScope installation path and then list all the dss scripts in the "scripts/automation" folder, but this can easily be changed.
Note that some functions of the FSO are very powerful and are open to abuse by virus writers. For this reason, good anti-virus software will often stop scripts running that use the FSO to access files. This is good news in the sense that it means that your anti-virus software is doing a good job, but it can be a nuisance too. You should be able to tell the anti-virus software to allow the script to run, but use this type of thing with care.
|Resource Type: Scripts and Automation
(File Download) |
Download Link (https:): Test_Selection.zip
Size: 2 KiB