Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Folder management scripts are often designed to work against any folder on a computer. Because of this, folder names and paths are typically not hard-coded into the script; instead, these values must be typed in as command-line arguments each time the script is run. This provides your script with the flexibility to work against any folder on a computer; however, it also requires you to know the exact location of each folder you want to manage and to correctly type that location before the script can run. This can be particularly cumbersome if the folder you want to manage has a name such as C:\System Administration\Administrator Tools\Diagnostics\Scripts\Network\IP Configuration.
If you are working with a single folder at a time, the Shell s Browse For Folder dialog box provides a graphical alternative to command-line arguments. Instead of requiring you to type in a folder path, the Browse For Folder dialog box (shown in Figure 11.4) allows you to select the folder from a standard Windows Explorer like tree control.
Figure 11.4 Browse For Folder Dialog Box
Browse For Folder Dialog Box
After you select a folder and click OK, your script is bound to the Folder object for the selected folder. If you are using a Shell object script, you can proceed to carry out the desired actions on that folder. If you want to pass the selected folder to the FileSystemObject or to WMI, your script can:
To display the Browse for Folder dialog box, use the Shell object s BrowseForFolder method along with the parameters shown in Table 11.6.
Table 11.6 BrowseForFolder Parameters
Parameter | Description |
---|---|
Window handle | Numeric ID to be assigned to the displayed dialog box. For scripts, this value should be 0. |
Title | Text string to be displayed inside the dialog box. The title typically represents instructions to the user; in Figure 11.4, the title is "Select a folder to compress:" |
Options | Optional values that can be used in constructing the dialog box. Two values are particularly useful in scripts:
To display the standard dialog box, set the Options to 0. |
Root folder | Optional parameter specifying the root folder shown at the top of the dialog box. If the root folder is set to C:\Scripts\ADSI, the folder ADSI appears at the top of the dialog box, and neither C:\Scripts nor C:\ is accessible. |
For example, the following code displays the Browse For Folder dialog box with these options:
Set objFolder = objShell.BrowseForFolder _ (0,
"Select a folder to compress:
", 0,
"D:\
")
Listing 11.8 contains a script that uses the Browse For Folder dialog box to return the path of a selected folder. To carry out this task, the script must perform the following steps:
To limit data retrieval to a specified folder, a Where clause is included restricting the returned folders to the folder selected from the Browse for Folder dialog box.
Listing 11.8 Using the Browse For Folder Dialog Box
|
|
Send us your feedback | « Previous | Next » |