Click to See Complete Forum and Search --> : delete file


jrthor2
08-10-2007, 09:51 AM
I have the below that deletes a file on the server. If the file is not there though, I get an error. How would I only delete the file if it is on the server?

if (Trim(Request.Form("link")) <> "") then
strPath = "/free_offerings/images/pdf/"
Filetodelete=server.mappath(Request.Form("link"))
'response.write("deleting file " & Filetodelete)
Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile(Filetodelete)
Set fs=nothing
end if

Thanks

Chikara
08-10-2007, 12:50 PM
File System Object overview
http://www.w3schools.com/asp/asp_ref_filesystem.asp


This link will show you how to test to see if a file exists. Just do this before you try to delete the file.
http://www.w3schools.com/asp/met_fileexists.asp