Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
As demonstrated in the preceding script, WMI can be used to bind to and retrieve the properties from a specific file system folder. In addition, WMI can be used to retrieve the properties for all the folders in the file system, allowing you to easily map the layout of your disk drives. Although you probably do not need to enumerate all the folders on a regular basis, carrying out this task on occasion can help you spot anomalies in the file system, including such things as folders that:
To retrieve a list of all the folders on a computer, use the following WQL query:
"SELECT * FROM Win32_Directory
"
If you want to limit data retrieval to a single disk drive, include a Where clause specifying the drive letter. For example, this query returns a list of all the folders on drive C:
"SELECT * FROM Win32_Directory WHERE Drive = 'C'
"
If you need to enumerate all the folders on a computer, be aware that this query can take an extended time to complete. For example, on a Windows 2000 based computer with 5,788 folders, a script that returns the name of each folder required 429 seconds to complete.
Listing 11.2 contains a script that returns a list of all of the folders on a computer. To carry out this task, the script must perform the following steps:
This returns a collection of all the folders on the computer.
Listing 11.2 Enumerating All the Folders on a Computer
|
|
Send us your feedback | « Previous | Next » |