Search Tools Links Login

deletefiles


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.

Original Author: Jason Buck

Inputs

passes a querystring delete=Yes to call the delete function and passes a querystring FN= the filename to be deleted.

Assumptions

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.

Returns

List of all files in the directory minus the deleted file.

Side Affects

Make sure you are clicking on the right file, because once you click on it, it is gone.

API Declarations

This code was written by Jason Buck for free distribution.

Code


delte a file

WARNING


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.

For help or comments, feel free to contact me at Hotmail
or visit my temporary site at www22.brinkster.com/jbuck


Click on any file below to delete it. I recommend adding a few junk files for demostration
purposes.



<%

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 " & strFN & "
"
  Set f1 = fso.GetFile(Server.MapPath(strFN))
  f1.Delete
  
  Response.Write "All done!
"
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 ""
    response.write tobdel.name & "

"

Next
%>

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 102 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.