ASP Delete file directory and directory all file code

Source: Internet
Author: User
Tags chr trim urlencode

Response.Expires =-1
Response.ExpiresAbsolute = Now ()-1
Response.Expires = 0
Response.CacheControl = "No-cache"
%>
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<%
Dim act,frompath,page
Dim Folder_name,file_name,fso,realpath,backurl
Act=lcase (Trim (Request.Form ("act")) & ""
Path=trim (Request.Form ("path")) & ""
Page=trim (Request.Form ("page")) & ""

If Path= "" Then
Path=trim (Request.QueryString ("path")) & ""
End If
If act= "" Then
Act=lcase (Trim (Request.QueryString ("act"))
End If
If page= "" Then
Page=lcase (Trim (request.querystring ("page"))
End If

If Right (path,1) <> "/" Then
path=path& "/"
End If
If left (path,1) <> "/" Then
Path= "/" &path
End If
If Invalidchar (path,0) Then
Call ShowMsg (Error: The specified path contains illegal characters!) ","")
Response.End
End If
Call Checkpath (Pathcanmodify,path)
Realpath=server.mappath (PATH)

Select Case Act
Case "Copy" and "Move"
Call Copymove ()
Case "Del", "RD", "MD", "Copycon", "Renfile", "Renfolder"
Call Commands ()
Case "Deltree"
Call Deltree ()
Case Else
Call ShowMsg ("parameter is missing, please do it again!") "," Back:off ")
Response.End
End Select

Sub Copymove ()
Checksubmit ()
Frompath=trim (Request.Form ("Frompath"))
If Invalidchar (frompath,0) Then
Call ShowMsg (Error: The specified path contains illegal characters!) ","")
Response.End
End If
Call Checkpath (Pathcanmodify,frompath)
Session (sessionprefix& "folders") = ""
Session (sessionprefix& "files") = ""
For each folder_name in Request.Form ("folders")
Session (sessionprefix& "folders") =session (sessionprefix& "Folders") & "| |" &folder_name
Next
If left (sessionprefix& "folders"), 2 = "| |" Then
Session (sessionprefix& "folders") =right (Sessions (sessionprefix& "Folders"), Len (Session sessionprefix& "Folders"))-2)
End If
For each file_name in Request.Form ("Files")
Session (sessionprefix& "files") =session (sessionprefix& "Files") & "| |" &file_name
Next
If left (sessionprefix& "files"), 2 = "| |" Then
Session (sessionprefix& "files") =right (sessionprefix& "Files"), Len (sessionprefix& " Files "))-2)
End If
If session (sessionprefix& "folders") = "" and session (sessionprefix& "files") = "" Then
Session (sessionprefix& "act") = ""
Session (sessionprefix& "frompath") = ""
Call ShowMsg ("error: No files and folders are selected!") ","")
Else
Session (sessionprefix& "Act") =act
Session (sessionprefix& "Frompath") =server.mappath (Frompath)
Response.Redirect "web_explorer.asp?path=" &server.urlencode (path) & "&page=" &page
End If
End Sub

Sub Commands ()
Frompath=server.urlencode ("Currentpath")
Set Fso=server.createobject ("Scripting.FileSystemObject")
Backurl= "web_explorer.asp?path=" &frompath& "&page=" &page
If act= "Del" Then
If Fso.fileexists (Realpath) Then
Fso.deletefile (Realpath)
If Fso.fileexists (Realpath) Then
Set fso=nothing
Call ShowMsg ("Error: Delete file failed!") Make sure you have the appropriate permissions. "," Back:off ")
Response.End
End If
Set fso=nothing
' Response.Redirect (Backurl)
Else
Set fso=nothing
Call ShowMsg ("error: File you want to delete" &getselfname (Realpath, "") & "does not exist!" "," Back:off ")
Response.End
End If
ElseIf act= "Rd" Then
If trim (path) = "/" Then
Call ShowMsg ("error: Unable to delete site root!") "," Back:off ")
Response.End
End If
If Fso.folderexists (Realpath) Then
Fso.deletefolder (Realpath)
If Fso.folderexists (Realpath) Then
Set fso=nothing
Call ShowMsg ("Error: Delete folder failed!") Make sure you have the appropriate permissions. "," Back:off ")
Response.End
End If
Set fso=nothing
' Response.Redirect (Backurl)
Else
Set fso=nothing
Call ShowMsg ("Error: folder you want to delete" &getselfname (Realpath, "") & "does not exist!" "," Back:off ")
Response.End
End If
ElseIf act= "MD" Then
If Fso.folderexists (Realpath) Then
Set fso=nothing
Call ShowMsg ("error: The directory you want to create" &getselfname (Realpath, "") & already exists! "," Back:off ")
Response.End
End If
Fso.createfolder (Realpath)
If not fso.folderexists (Realpath) Then
Set fso=nothing
Call ShowMsg ("Error: New directory failed!") Make sure you have the appropriate permissions. "," Back:off ")
Response.End
End If
Set fso=nothing
' Response.Redirect (Backurl)
ElseIf act= "Copycon" Then
If Fso.fileexists (Realpath) Then
Set fso=nothing
Call ShowMsg ("error: The file you want to create" &getselfname (Realpath, "") & already exists! "," Back:off ")
Response.End
End If
Fso.createtextfile (Realpath)
If not fso.fileexists (Realpath) Then
Set fso=nothing
Call ShowMsg ("Error: New file failed!") Make sure you have the appropriate permissions. "," Back:off ")
Response.End
End If
Set fso=nothing
' Response.Redirect (Backurl)
ElseIf act= "Renfile" or act= "Renfolder" Then
Dim Oldname,newname,addchar
Oldname=trim (Request ("Oldname"))
Newname=trim (Request ("NewName"))
If act= "Renfolder" Then
addchar= "Clip"
End If
If Oldname= "" or newname= "" Then
Set fso=nothing
Call ShowMsg ("Error: Old file" &addchar& "name and new file" &addchar& "names must not be empty!) "," Back:off ")
Response.End
ElseIf Invalidchar (oldname,1) Then
Set fso=nothing
Call ShowMsg ("Error: Old file" &addchar& "name contains illegal characters!) "," Back:off ")
Response.End
ElseIf Invalidchar (newname,1) Then
Set fso=nothing
Call ShowMsg ("Error: New file" &addchar& "name contains illegal characters!) "," Back:off ")
Response.End
End If
Oldname=server.mappath (Path&oldname)
Newname=server.mappath (Path&newname)
If act= "Renfile" Then
If Fso.fileexists (oldname) Then
If not fso.fileexists (newname) Then
Fso.getfile (oldname). Name=trim (Request ("NewName"))
If not fso.fileexists (newname) Then
Set fso=nothing
Call ShowMsg (Error: Change file "&addchar&" name failed!) Make sure you have the appropriate permissions. "," Back:off ")
Response.End
End If
Set fso=nothing
' Response.Redirect (Backurl)
Else
Set fso=nothing
Call ShowMsg ("failed: New file" &addchar& "&trim" (Request ("NewName")) & "The file" &addchar& "already exists! "," Back:off ")
Response.End
End If
Else
Set fso=nothing
Call ShowMsg ("failed: File to change &addchar&" &trim (Request ("Oldname")) & "does not exist!" "," Back:off ")
Response.End
End If
ElseIf act= "Renfolder" Then
If Fso.folderexists (oldname) Then
If not fso.folderexists (newname) Then
Fso.getfolder (oldname). Name=trim (Request ("NewName"))
If not fso.folderexists (newname) Then
Set fso=nothing
Call ShowMsg (Error: Change file "&addchar&" name failed!) Make sure you have the appropriate permissions. "," Back:off ")
Response.End
End If
Set fso=nothing
' Response.Redirect (Backurl)
Else
Set fso=nothing
Call ShowMsg ("failed: New file" &addchar& "&trim" (Request ("NewName")) & "The file" &addchar& "already exists! "," Back:off ")
Response.End
End If
Else
Set fso=nothing
Call ShowMsg ("failed: File to change &addchar&" &trim (Request ("Oldname")) & "does not exist!" "," Back:off ")
Response.End
End If
End If
End If
End Sub

Sub Deltree ()
Checksubmit ()
Dim folders,files,foldername,filename,tempname
Frompath=trim (Request.Form ("Frompath"))
If Invalidchar (frompath,0) Then
Call ShowMsg (Error: The specified path contains illegal characters!) ","")
Response.End
End If
Call Checkpath (Pathcanmodify,frompath)
Frompath=server.mappath (Frompath)
Backurl= "web_explorer.asp?path=" &server.urlencode (path) & "&page=" &page

If LCase (Trim (Request.Form ("act")) = "deltree" Then
Set Folders=request.form ("Folders")
Set Files=request.form ("Files")
Set Fso=server.createobject ("Scripting.FileSystemObject")
If Folders.count>0 Then
For each foldername in folders
tempname=frompath& "" &foldername
If Fso.folderexists (tempname) Then
Fso.deletefolder Tempname,true
End If
Next
End If
If Files.count>0 Then
For each filename in files
tempname=frompath& "" &filename
If Fso.fileexists (tempname) Then
Fso.deletefile Tempname,true
End If
Next
End If
Set folders=nothing
Set files=nothing
Set fso=nothing
End If
' Response.Redirect (Backurl)
End Sub

If Trim (backurl) & "<>" "Then
 backurl=replace (Backurl," "," \ ")
 backurl=replace ( BACKURL,CHR, "&CHR"
End If
%>
<script language= "Web Effects"
Alert ("Execute operation ended!"). ");
try{
 parent.location.reload ();
} catch (e) {};
this.location.href= "About:blank";
</script>
<body></body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.