Delete Method

Deletes a specified file or folder.

                      force ); 


  • object
    Required. Always the name of a File or Folder object.

  • force
    Optional. Boolean value that is True if files or folders with the read-only attribute set are to be deleted; False (default) if they are not.


An error occurs if the specified file or folder does not exist.

The results of the Delete method on a File or Folder are identical to operations performed using FileSystemObject.DeleteFile or FileSystemObject.DeleteFolder.

The Delete method does not distinguish between folders that have contents and those that do not. The specified folder is deleted regardless of whether or not it has contents.

The following example illustrates the use of the Delete method.

var fso, f;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.CreateTextFile("c:\\testfile.txt", true);
f.WriteLine("This is a test.");
f = fso.GetFile("c:\\testfile.txt");
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
Set MyFile = fso.GetFile("c:\testfile.txt")

Applies To:

File Object| Folder Object

See Also


Copy Method (FileSystemObject)

DeleteFile Method

DeleteFolder Method

Move Method

OpenAsTextStream Method