Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Folders are not necessarily permanent additions to a file system. At some point, folders might need to be deleted, perhaps because they are no longer required, because the role of the computer has changed, or because the folders were created by mistake.
The Win32_Directory class includes a Delete method that allows you to delete folders: you simply bind to the folder in question and then call the Delete method. After the Delete method is called, the folder is permanently removed from the file system; it is not sent to the Recycle Bin. In addition, no confirmation notice ("Are you sure you want to delete this folder?") is issued. Instead, the folder is immediately removed.
You cannot delete read-only folders using the FileSystemObject; however, this can be done using WMI. If your script uses WMI and you do not want to remove a read-only folder, you must use the Readable property to check the folder status before deleting it.
Listing 11.14 contains a script that deletes the folder C:\Scripts. 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 those with the name C:\\Scripts. You must include both backslashes (\\) in the name.
Listing 11.14 Deleting Folders
|
|
Send us your feedback | « Previous | Next » |