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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete selected files

Status
Not open for further replies.

chellweg

IS-IT--Management
Dec 8, 2003
20
US
I have the following script that lists the files in a different directory and generates hyperlinks to them to download them with a check box next to them. I want to be able to delete the selected files I know I can use the file system object to delete files, just don't know how to have it loop through and delete each of the selected files. I would also like to have this submit to itself, and call a function on submit to handle the delete, instead of having 2 different asp files. Here is current source:




<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>Gungor Productions File Exchange</TITLE>
<style>
BODY {background-color: white;font-family:arial; font-size:12}
</style>
</HEAD>
<BODY>
<p align=&quot;center&quot;><b><font size=&quot;5&quot;>Gungor Productions File Exchange Management Interface</font></b></p>
<div style=&quot;border-bottom: #A91905 2px solid;font-size:16&quot;><br><strong>Select files to delete from Server:</strong></div>
<%
Dim strPath 'Path of directory to show
Dim objFSO
Dim objFolder
Dim objItem
strPath=&quot;./files&quot;
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
response.write &quot;<form method=&quot;&quot;POST&quot;&quot; action=&quot;&quot;manage.asp&quot;&quot; onSubmit=&quot;&quot;return onSubmitForm();&quot;&quot;><TABLE>&quot; &_
&quot;<tr><TD></TD><TD><strong>File Name</td></strong>&quot; &_
&quot;<TD><strong>Size</strong></TD></TR>&quot;
For Each objItem In objFolder.Files
response.write &quot;<tr><TD><input type=&quot;&quot;checkbox&quot;&quot; name=&quot;&quot;&quot; & objItem.Name & &quot;&quot;&quot; value=&quot;&quot;ON&quot;&quot;></TD><TD><A HREF=&quot;&quot;&quot; &_
strPath & objItem.Name &_
&quot;&quot;&quot;>&quot; & objItem.Name & &quot;</A></TD>&quot; &_
&quot;<TD>&quot; & objItem.Size & &quot;</TD></TR>&quot;
Next
response.write &quot;</TABLE><p><input type=&quot;&quot;submit&quot;&quot; value=&quot;&quot;Delete Selected Files&quot;&quot; name=&quot;&quot;B1&quot;&quot;></p></form>&quot;
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
<p align=&quot;right&quot;><font face=&quot;Verdana&quot; size=&quot;1&quot;>©2004, Gungor Productions.
All Rights Reserved.</font></p>
</BODY>
</HTML>
 
This hopefully points you in the direction:




<%@ Language=VBScript %>
<%
if request.ServerVariables(&quot;REQUEST_METHOD&quot;) = &quot;POST&quot; then
response.Write request.Form(&quot;fFilelist&quot;)
' so know you know which files you must delete!
end if


Dim strPath
Dim objFSO
Dim objFolder
Dim objItem
strPath=&quot;/&quot;
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
response.write &quot;<form method=&quot;&quot;POST&quot;&quot; action='759469.asp'><TABLE>&quot; &_
&quot;<tr><TD></TD><TD><strong>File Name</td></strong>&quot; &_
&quot;<TD><strong>Size</strong></TD></TR>&quot;
For Each objItem In objFolder.Files
response.write &quot;<tr><TD><input type=&quot;&quot;checkbox&quot;&quot; name=fFilelist value=&quot;&quot;&quot; & objItem.Name & &quot;&quot;&quot;></TD><TD><A HREF=&quot;&quot;&quot; &_
strPath & objItem.Name &_
&quot;&quot;&quot;>&quot; & objItem.Name & &quot;</A></TD>&quot; &_
&quot;<TD>&quot; & objItem.Size & &quot;</TD></TR>&quot;
Next
response.write &quot;</TABLE><p><input type=&quot;&quot;submit&quot;&quot; value=&quot;&quot;Delete Selected Files&quot;&quot;></p></form>&quot;
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>






hth,
Foxbox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top