Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Deleting files is as an integral part of file management. Files need to be deleted for many reasons: to free up disk space; to remove outdated files; to remove inappropriate files. WMI is a powerful tool for deleting files because it allows you to select a specified set of files (regardless of their physical location in the file system) and then delete all those files in a single operation.
For example, you might have a policy that prohibits users from storing media files on a particular file server. A WMI script can be scheduled to run each night, search for a specific set of files (for example, .mp3 or .wma files), and then delete all instances of that file type.
Unlike the FileSystemObject, the WMI Delete method automatically deletes read-only files. If you do not want to delete read-only files, you have to construct your query in such a way as to exclude these files from the returned collection (for example, by including the clause Where Readable = True).
Listing 11.26 contains a script that deletes all the Windows Media files from a computer. To carry out this task, the script must perform the following steps:
To limit data retrieval to Windows Media files, a Where clause is included restricting the returned files to those with the extension .wma.
Listing 11.26 Deleting Files
|
|
Send us your feedback | « Previous | Next » |