DeleteFolder method of Javascript fileSystemObject (FSO) provides the functionality to delete the specified folder from the client’s PC. Javascript FSO DeleteFolder method could perform its action only if the security permissions of web browser at client’s end allow your web page to create the FSO object via Javascript Automation server and access the file system to delete the specified folder. If folder exits at the specified location then DeleteFolder method deletes the folder otherwise throws an error. You can also delete multiple folders at the specified location by passing wild card characters to the DeleteFolder method e.g.: *abc*, wildcard will delete all the folder with name having specified name pattern. DeleteFolder method deletes the folder as well as its contents i.e. all the files stored in the specified folder.
Syntax for Javascript FSO DeleteFolder Method
fso.DeleteFolder(folderSpec, [Force]);
DeleteFolder method of FSO accepts two types of parameters as shown in the above syntax:
1. FolderSpec: this parameter accepts the location and folderName that is to be deleted. Wildcard characters are also allowed to delete the multiple folders at the same location.
2. Force: optional. This parameter accepts Boolean value i.e. 0/1 or true or false. If true then DeleteFolder will delete the read-only files otherwise not. By Default its value is false. DeleteFolder method does not delete read-only folder and files.
Example for Javascript FSO DeleteFolder Method
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CreateFolder("C:\\Temp\\myFolder");
fso.DeleteFolder("C:\\Temp\\myFolder", true);
fso.CreateFolder("C:\\Temp\\folder1");
fso.CreateFolder("C:\\Temp\\folder2");
fso.CreateFolder("C:\\Temp\\folder3");
fso.DeleteFolder("C:\\Temp\\*folder*", true);
fso = null;
</script>
Continue to next tutorial: Javascript FSO DriveExists Method to learn checking whether the specified drive exists or not.