VB icon

deletefiles

Email
Submitted on: 1/5/2015 5:07:00 PM
By: Jason Buck (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 698
 
     This ASP page is a maintenance tool of sorts. It first lists all of the files in the directory. The links when pressed pass the file name back to the same page which calls a delete function that delete the file which was just clicked on.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :deletefiles
'**************************************
This code was written by Jason Buck for free distribution.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: deletefiles
' Description:This ASP page is a maintenance tool of sorts. It first lists all of the files in the directory. 
The links when pressed pass the file name back to the same page which calls a delete function that delete the file which was just clicked on.
' By: Jason Buck (from psc cd)
'
' Inputs:passes a querystring delete=Yes to call the delete function and passes a querystring FN= the filename to be deleted.
'
' Returns:List of all files in the directory minus the deleted file.
'
' Assumes:This code uses the Filesystemobject, passes variables via a querystring, and use a for each loop.
Again, make sure you want to delete the file before clicking.
'
' Side Effects:Make sure you are clicking on the right file, because once you click on it, it is gone.
'**************************************

<html><head>
<title>delte a file</title>
</head><body>
<center><H2>WARNING</H2></center>
This code is very dangerous. When loaded, clicking on any file on this page
will cause that file to be deleted. I have not put in a confirm delete page.
I recommend doing so if you are ever going to use this delete function in a production 
environment.
<p>For help or comments, feel free to contact me at <a href="mailto:buck_jason@hotmail.com">Hotmail</a> 
or visit my temporary site at <a href="http://www22.brinkster.com/jbuck">www22.brinkster.com/jbuck</a>
<p>
Click on any file below to delete it. I recommend adding a few junk files for demostration
purposes.<p>
<%
strdelete = request.querystring("delete")
strFN = request.querystring("FN")
if strdelete = "Yes" Then
call functionDF()
End if
Sub functionDF()
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Response.Write "Deleting file <b>" & strFN & "</b><br>"
Set f1 = fso.GetFile(Server.MapPath(strFN))
f1.Delete
Response.Write "All done!<br>"
End Sub
' the dot . below represents the current directory that this file is in.
' this file will only delete in its current directory. to delete in
' directories, you would have to add that to the tobdel portion which is the FN
' that is being passed.
dirtowalk = "."
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(server.mappath(dirtowalk))
Set fc = f.Files
For Each tobdel in fc
response.write "<a href='deletefiles.asp?delete=Yes&FN=" & tobdel.name & "'>"
response.write tobdel.name & "</a></br>"
Next
%>
</body></html>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.