Javascript FSO DeleteFile Method
DeleteFile method of Javascript fileSystemObject (FSO) provides the functionality to delete the specified file from the client’s PC. Javascript FSO DeleteFile 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 file. If file exits at the specified location then DeleteFile method deletes the file otherwise throws an error. You can also delete multiple file at the specified location by passing wild card characters to the DeleteFile method e.g.: *.txt wildcard will delete all the files with txt extension.
Syntax for Javascript FSO DeleteFile Method
fso.DeleteFile(fileSpec, [Force])
DeleteFile method of FSO accepts two types of parameters as shown in the above syntax:
1. FileSpec: this parameter accepts the location and filename that is to be deleted. Wildcard characters are also allowed to delete multiple files at the same location.
2. Force: optional. This parameter accepts Boolean value i.e. 0/1 or true or false. If true then DeleteFile will delete the read-only files otherwise not. By Default its value is false. DeleteFile method does not delete read-only files.
Example for Javascript FSO Delete File Method
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.DeleteFile("C:\\Temp\\myFolder\\file.txt", true);
// OR
fso.DeleteFile("C:\\Temp\\myFolder\\*.txt", true);
fso = null;
</script>
Continue to next tutorial: Javascript FSO DeleteFolder Method to learn how to remove a directory from client's PC.
