List and delete files

Enables users to list and delete files

Public
Tested
My Own Work
'**************************************
' Name: DeleteFiles+
' Description:'
'Based on the original DeleteFiles by Jason Buck, this ASP page
'allows the user to list and delete files in the directory in which it resides.
'
'The modifications include an "are you sure" screen,
'displaying an image file, hiding this script itself so it won't be listed and
'css buttons.
' By: David Felton
'
' Inputs:'
'QueryStrings are still passed to dispaly the screens and delete the files.
'
'file=file or file=image
'Distingushes between images and other file types
'
'delete=show,delete=sure, or delete=yes
'will show a file, display the are you sure screen and
'lastly call the delete function
'
'FN=passes which file will be deleted
'
' Returns:'
'list of files in the directory,
'display of an image/file name
'are you sure screen
'confirmation of deletion screen
'
' Side Effects:'
'Simple... the file is GONE and cannot be undone.
'
'This code is copyrighted and has ' limited warranties.Please see
' http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.6798/lngWId.4/qx/vb/scripts/ShowCode.htm 'for details. '**************************************
<HTML>
<HEAD>
<TITLE>Delete a File</TITLE>
<!-- This style creates the buttons For the script -->
<style>
<!--
body, td, li, p, table, input
 {
 font-family:   Verdana, Arial, Helvetica, sans-serif;
 font-size:    8pt;
 }
a:hover.Button 
 {
 color:    #FF0000;
 background:   #CCCCCC;
 }
A.Button
 {
 text-decoration: none;
 color:    #000000;
 background:   #CCCCCC;
 }
.Button
 {
 text-align:   center;
 text-decoration: none;
 color:    #000000;
 background:   #CCCCCC;
 border-top:   2px solid #EEEEEE;
 border-left:  2px solid #EEEEEE;
 border-right:  2px solid #999999;
 border-bottom:  2px solid #999999;
 font-family:  Verdana, Arial, Helvetica, sans-serif;
 font-size:   8pt;
 padding-left:  4;
 padding-right:  4;
 padding-top:  2;
 padding-bottom:  2;
 }
 -->
 </style>
</HEAD>

<BODY>

 <P align="center"><FONT size="6" color="#FF0000">File Deletion</FONT></P>
<%
strdelete = request.querystring("delete")
strFN = request.querystring("FN")
strFT = request.querystring("file")
'display the SHOW-ME-THE-FILE screen
if strdelete = "Show" Then
 if strFT = "image" Then
  response.write "<P align=center> <Img width=320 height=240 src=" & strFN & "><BR><BR>"
  response.write "<A class=button href=default.asp?file=image&delete=Sure&FN=" & strFN & ">Delete?</A> "
  response.write "<A class=button href=default.asp>List Files</A> <BR><BR></P>"
 Else
  response.write "<P align=center><FONT color=Blue size=5>" & strFN & "</FONT><BR><BR>"
  response.write "<A class=button href=default.asp?file=file&delete=Sure&FN=" & strFN & ">Delete?</A> "
  response.write "<A class=button href=default.asp>List Files</A> <BR><BR></P>"
 End if
 response.end
End if
'display the ARE-YOU-SURE screen
if strdelete = "Sure" Then
 if strFT = "image" Then
  response.write "<P align=center> <Img width=320 height=240 src=" & strFN & "><BR><BR>"
  response.write "<FONT color=Red size=5>Are You Sure You Want To Delete This File?</FONT><BR>"
  response.write "<A class=button href=default.asp?delete=Yes&FN=" & strFN & ">Yes, Delete It.</A> "
  response.write "<A class=button href=default.asp>NO, Do Not Delete It!</A> <BR><BR></P>"
 Else
  response.write "<P align=center><FONT color=Blue size=5>" & strFN & "</FONT><BR><BR>"
  response.write "<FONT color=Red size=5>Are You Sure You Want To Delete This File?</FONT><BR>"
  response.write "<A class=button href=default.asp?delete=Yes&FN=" & strFN & ">Yes, Delete It.</A> "
  response.write "<A class=button href=default.asp>NO, Do Not Delete It!</A> <BR><BR></P>"
  End if
  response.end
End if
'call the delete function
if strdelete = "Yes" Then
 call functionDF()
End if

'the delete function
Sub functionDF()
 Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
 Set f1 = fso.GetFile(Server.MapPath(strFN))
 f1.Delete
  Response.Write "<P align=center>File <B>" & strFN & "</B> Deleted! <BR><BR>"
  Response.Write "<A class=button href=default.asp>Return To List</A><BR></P>"
  Response.End
End Sub
'view files in this directory
dirtowalk = "./"

'display the files
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(server.mappath(dirtowalk))
Set fc = f.Files
 response.write "<HR>"
 response.write "<P><FONT size=5 >File List</FONT></P> "
For Each tobdel In fc

'dont display this page
 if tobdel.name = "default.asp" Then
   response.write ""
'is the file an image?
 ElseIf right(tobdel.name, 4) = ".jpg" Then
   response.write "<A class=button href=default.asp?file=image&delete=Show&FN=" & tobdel.name & "><I><B>View</B></I></A> "
  response.write "<A class=button href=default.asp?file=image&delete=Sure&FN=" & tobdel.name & "><I><B>Del</B></I></A> " & tobdel.name & "<BR><BR>"
 ElseIf right(tobdel.name, 4) = ".gif" Then
   response.write "<A class=button href=default.asp?file=image&delete=Show&FN=" & tobdel.name & "><I><B>View</B></I></A> "
  response.write "<A class=button href=default.asp?file=image&delete=Sure&FN=" & tobdel.name & "><I><B>Del</B></I></A> " & tobdel.name & "<BR><BR>"
 ElseIf right(tobdel.name, 4) = "jpeg" Then
   response.write "<A class=button href=default.asp?file=image&delete=Show&FN=" & tobdel.name & "><I><B>View</B></I></A> "
  response.write "<A class=button href=default.asp?file=image&delete=Sure&FN=" & tobdel.name & "><I><B>Del</B></I></A> " & tobdel.name & "<BR><BR>"
'...or another file type
 Else
   response.write "<A class=button href=default.asp?file=file&delete=Show&FN=" & tobdel.name & "><I><B>View</B></I></A> "
  response.write "<A class=button href=default.asp?file=file&delete=Sure&FN=" & tobdel.name & "><I><B>Del</B></I></A> " & tobdel.name & "<BR><BR>"
 End if
Next

%>
</P>

</BODY>
</HTML>

Views 3395 Downloads 1010

Classic ASP File System
DavidFelton
1
Revisions

v1.0