Bewerken

Delen via


Delete method of the Win32_Directory class

The Delete WMI class method will delete the logical file (or directory) specified in the object path.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 Delete();

Parameters

This method has no parameters.

Return value

Returns a value of 0 (zero) if the file was successfully deleted, and any other number to indicate an error.

0

The request was successful.

2

Access was denied.

8

An unspecified failure occurred.

9

The name specified was not valid.

10

The object specified already exists.

11

The file system is not NTFS.

12

The platform is not Windows.

13

The drive is not the same.

14

The directory is not empty.

15

There has been a sharing violation.

16

The start file specified was not valid.

17

A privilege required for the operation is not held.

21

A parameter specified is not valid.

Remarks

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.

Delete 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.

Examples

The following VBScript code sample deletes the folder C:\Scripts.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Directory WHERE Name = 'c:\\Scripts'")
For Each objFolder in colFolders
 errResults = objFolder.Delete
 Wscript.Echo errResults
Next

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

See also

Operating System Classes

Win32_Directory