Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete from directory

Status
Not open for further replies.

carranz

Technical User
Nov 17, 2006
40
US
I have a page that shows a list of files. I would like to select one of the files then direct me to another page so I can delete that single file

here is my code for the list of files
Dim folder
Set folder = fso.GetFolder(Server.MapPath("/web/file1/file2/"))

If folder.Size > 0 Then
Response.Write "<ul>"
For Each file In folder.Files
Response.Write "<a href=""/web/file1/file2/"
Response.Write file.Name & """>"
Response.Write "<b>" & file.Name
Response.Write "(Date: "& file.DateCreated & ") "
Next
Response.Write "</ul>"
Else
Response.Write "<ul><li type=""circle"">No Files Uploaded.</ul>"
End If
%>

then on the other page this is the code I'm looking at for deleting the file

<%
dim fs
Set fs=Server.CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile("c:\test.txt",True)
if fs.FileExists("c:\test.txt") then
fs.DeleteFile("c:\test.txt")
end if
set fs=nothing
%>

any help would be appreciated
 
When I've made pages like this I tend to have it all happen on the same page. When constructing the link to the individual file you can have the href point to the same page, just put on a querystring something like:
Code:
Response.Write "<a href=""/web/file1/file2/"
Response.Write "[COLOR=blue]?action=delete&dfile=" & file.Name & """>[/color]"
Then the page just needs to process itself -- right at the top of the asp file I would check for Request.Querystring("action")="delete" and then do the file deletion code, and at the end you would redirect to the same page to remove the delete querystring. I'd also add a javascript confirm to the href that deletes the file to make sure the user knows what he's getting into.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top