SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Deleting File by using DeleteFile

We 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
FilePath=Server.MapPath("images/myfile.asp")
Set FSOobj = Server.CreateObject("Scripting.FileSystemObject")
if FSOobj.fileExists(FilePath) Then

Response.Write "file Exist"
Response.Write "<br>Deleted file "&FSOobj.DeleteFile(FilePath)
Else
Response.Write "File does not exist"
End if
Set FSOobj = Nothing


We can check the file extension and use one if condition to delete only a particular type of file.
Further readings
Server.MapPath to convert virtual path to physical path of files and directory.
FileSystemObject:Checking file or folder exist by using File system object .
Getting the file name from full path of the current running script in ASP.
Getting the file extension and file name by using FSO
Deleting file by using DeleteFile in FSO
Getting the Last updating and creation date and time of a file.
Listing all files present inside a folder using FileSystemObject
Reading data from a text file using File System Object
Writing data to a text file using File System Object
Read & Writing data to a text file: Developing a page hit counter
Appending data to a text file: Storing emails in a text file
 
Scripts
PHP
JavaScript
All ASP Tutorials
File Management
MapPath
FileSystemObject
append
name
Updating Time
Listing all files
Reading file
Writing file
Read & Write
File type
Delete File
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.