PDA

View Full Version : Adding and deleteing folders


mdlister
12-09-2005, 09:18 PM
Hi very new to the whole asp scene and have been lookin through number of sites looking how to create a dir and delete a dir from one page. So far i have been about to create folders by passing the specified folder name through a query string but now i am havin trouble adding the delete folder button as it seems both buttons are creating folders and it is not lookin at my if statement to determine if either create or delete have been pressed.

i wondered if any one would know an easier way or what is wrong and how to fix it? my site is running from my local host at the moment at

http://82.32.240.16/jsonline/admin/tester.asp

<html>
<body>
<form name="form1" action="tester.asp" method="get">
<input type="text" name="fname" size="20" />
<input type="submit" name="One" value="create"/>
<input type="submit" name="Two" value="delete"/>
</form>
<%
dim fname
Dim fs
Dim f
fname=Request.QueryString("fname")
If Request.Form("One") <> "create" Then Response.Write "First button pressed"
Request.QueryString("fname")
Set fs=Server.CreateObject("Scripting.FileSystemObject")

If fs.FolderExists("c:\inetpub\wwwroot\jsonline\images\" + fname) = true Then
Response.Write("Folder <b>" + fname + "</b> already exists!")
Else
set f=fs.CreateFolder("c:\inetpub\wwwroot\jsonline\images\" + fname)
Response.Write("Folder <b> " + fname + "</b> Created!")

end if

set f=nothing
set fs=nothing

If Request.Form("Two") <> "delete" Then Response.Write "Second button pressed"
if fs.FolderExists("c:\inetpub\wwwroot\jsonline\images\" + fname) then
fs.DeleteFolder("c:\inetpub\wwwroot\jsonline\images\" + fname)
Response.Write("Folder <b> " + fname + "</b> Deleted")
Else
Response.Write("Folder <b> " + fname + "</b> not there")
end if
%>



</body>
</html>

angst
12-09-2005, 09:52 PM
well,
this is because your using two submit buttons,

<html>
<body>
<form name="form1" action="tester.asp" method="get">
<input type="text" name="fname" size="20" />
<input type="submit" name="One" value="create"/> \
<input type="submit" name="Two" value="delete"/> / these are both the exact same function, so simply submit the form
</form>

maybe try using a radio switch.

like:

<html>
<body>
<form name="form1" action="tester.asp" method="get">
<input type="text" name="fname" size="20" /><br />
Make Folder <input type="radio" name="folderaction" value="make"><br />
Delete Folder <input type="radio" name="folderaction" value="delete"><br />
<input type="submit" name="One" value="Continue"/>
</form>

then just use:

If request("folderaction")="make" Then
..make the folder code..
Else If request("folderaction")="delete" Then
..delete folder code..
End If


hope this helps,
-Ken

mdlister
12-10-2005, 12:06 PM
thanx ken i'll give that a go after work tonight and let u know how it goes