Deleting File by using DeleteFileWe can delete a file by using File system object or FSO in Active Server Page (
ASP). We can delete the file by using DeleteFile object. We will use the same FSO and server Map Path to define the path of the file to be deleted.
Before applying the delete command we will be checking if the file is there or not by using file exist command.
Here is the code.
Dim OpenFileobj, FSOobj,FilePath
Set FSOobj = Server.CreateObject("Scripting.FileSystemObject")
if FSOobj.fileExists(FilePath) Then
Response.Write "file Exist"
Response.Write "<br>Deleted file "&FSOobj.DeleteFile(FilePath)
Response.Write "File does not exist"
Set FSOobj = Nothing
We can check the file extension and use one if condition to delete only a particular type of file.