Name
FileSystemObject.DeleteFolder Method
Syntax
oFileSysObj.DeleteFolderFileSpec[,Force]
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
FileSpecUse: Required
Data Type: String
The name and path of the folders to delete.
ForceUse: Optional
Data Type: Boolean
If set to
True, the read-only flag on a file is ignored and the file deleted. By default, its value isFalse; read-only files will not be deleted.
Description
Removes a given folder and all its files and subfolders.
Rules at a Glance
FileSpeccan contain wildcard characters as the final path component, which allows multiple folders that meet the file specification to be deleted.FileSpeccan’t end with a path separator.FileSpeccan be a relative or absolute path.If any of the files within the specified folders are open, the method fails with a “Permission Denied” error.
The DeleteFolder method deletes all contents of the given folder, including other folders and their contents.
If the specified folder can’t be found, the method fails.
Programming Tips and Gotchas
If an error occurs while deleting more than one file or folder, the DeleteFolder method exits immediately, thereby leaving the rest of the folders or files undeleted. There is also no rollback facility to undo the deletions prior to the error.
DeleteFolder permanently deletes folders and their contents; it doesn’t move them to the Recycle Bin.
The DeleteFolder method differs from the Delete method of the Folder object in two respects. First, it ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access