FSO Operations sample (for beginners)

Source: Internet
Author: User
Tags modify reset servervariables
fso| Beginners | example


Save the following code in an ASP file to facilitate the management of files on the server
<title>http://bbs.asp2004.net production: Small Gray qq:103895</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >
<!--
a:link {
font-size:9pt;
}
a:visited {
font-size:9pt;
}
a:hover {
font-size:9pt;
}
a:active {
font-size:9pt;
}
Body {
font-size:9pt;
margin-left:0px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
line-height:20px;
}
TD {
font-size:9pt;
line-height:20px;
}
-->
</style>
<%
Action=request. QueryString ("Action")
Temp=split (Request. ServerVariables ("URL"), "/"
Url=temp (UBound (temp))
Chklogin ()
Select Case Action
Case "Logout"
Logout ()
Case "Delfile"
Delfile ()
Case "SaveFile"
SaveFile ()
Case "Editfile"
Fileedit ()
Case "NewFile"
FileNew ()
Case "Upload"
Upload ()
Case "Saveupload"
Saveupload ()
Case "Delfolder"
Delfolder ()
Case "Savefolder"
Savefolder ()
Case "Editfolder"
Editfolder ()
Case "NewFolder"
NewFolder ()
Case Else
Foldername=request. QueryString ("foldername")
Filename=request. QueryString ("filename")
Path=foldername
If Path= "" then Path=server. MapPath ("./")
Showfolderlist (PATH)
End Select

Function showfolderlist (FOLDERSPEC)
Temp=request. ServerVariables ("Http_referer")
Temp=left (Temp,instrrev (temp, "/"))
Temp1=len (FOLDERSPEC)-len (server. MapPath ("./"))-1
If Temp1>0 Then
Temp1=right (Folderspec,cint (TEMP1))
ElseIf Temp1=-1 Then
Temp1= ""
End If
Tempurl=temp+replace (Temp1, "\", "/") + "/"
Set fso = CreateObject ("Scripting.FileSystemObject")
Upfolderspec=fso. Getparentfoldername (folderspec& "\")
%>
<a href= "<%= url%>?action=newfolder&foldername=<%= folderspec%>" > new Folder </a> | <a href= "<%= url%>?action=newfile&filename=<%= folderspec&" \ "%>" > new File </a> | <a href= "<%= url%>?action=upload" > upload file </a> | <a href= "<%= url%>?foldername=<%= upfolderspec%>" > Up </a> | <a href= "file.asp" > Back Home </a> | <a href= "<%= url%>?action=logout" > Exit </a>
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "1" bgcolor= "#6595D6" >
<tr bgcolor= "#E4E8EF" >
&LT;TD width= "64%" ><div align= "center" > Name </div></td>
&LT;TD width= "7%" ><div align= "right" > Size </div></td>
&LT;TD width= "6%" ><div align= "center" > Type </div></td>
&LT;TD width= "15%" ><div align= "left" > Modify Time </div></td>
&LT;TD width= "8%" ><div align= "center" > Operations </div></td>
</tr>
<%
' List directory
Set f = fso. GetFolder (FOLDERSPEC)
Set FC = F.subfolders
For each F1 in FC
%>
<tr bgcolor= "#E4E8EF" onmouseout=this.bgcolor= ' #E4E8EF '; Onmouseover=this.bgcolor= ' #FFFFFF ';>
<td><a href= "<%= url%>?foldername=<%= folderspec%>\<%= f1.name%>" ><%= f1.name%> </a></td>
<td><div align= "right" ><%= f1.size%></div></td>
<td><div align= "Center" > Folder </div></td>
<td><div align= "left" ><%= f1.datelastmodified%></div></td>
<td><a href= "<%= url%>?action=editfolder&foldername=<%= folderspec&" \ "&f1.name%> "> Modification </a> <a href=" <%= url%>?action=delfolder&foldername=<%= folderspec& "\" & F1.name%> "onclick=" {if (Confirm (' Delete folder <<%= f1.name%>>? ')) {return true;} return false;} " > Delete </a></td>
</tr>
<%
Next
' List files
Set FC = F.files
For each F1 in FC
%>
<tr bgcolor= "#E4E8EF" onmouseout=this.bgcolor= ' #E4E8EF '; Onmouseover=this.bgcolor= ' #FFFFFF ';>
<td><a href= "<%= tempurl+f1.name%>" target= "_blank" ><%= f1.name%></a></td>
<td><div align= "right" ><%= f1.size%></div></td>
<td><div align= "left" ></div></td>
<td><div align= "left" ><%= f1.datelastmodified%></div></td>
<td><a href= "<%= url%>?action=editfile&filename=<%= folderspec&" \ "&f1.name%>" > Modify </a> <a href= "<%= url%>?action=delfile&filename=<%= folderspec&" \ "&f1.name% > "onclick=" {if confirm (' Delete file <<%= f1.name%>>? ')) {return true;} return false;} " > Delete </a></td>
</tr>
<%
Next
Set fso=nothing
%>
</table>
<%
End Function
' File operation
function Delfile ()
Filename=request. QueryString ("filename")
Set Fso=server. CreateObject ("Scripting.FileSystemObject")
Fso.deletefile (filename)
tempurl=url& "Foldername=" &fso. Getparentfoldername (filename)
Set fso=nothing
Response. Redirect (Tempurl)
End Function

function SaveFile ()
Filename=request. Form ("filename")
Content=request. Form ("content")
Filename1=request. Form ("filename1")
If request. ServerVariables ("path_translated") <>filename Then
Set Fso=server. CreateObject ("Scripting.FileSystemObject")
Set F1=fso.opentextfile (filename,2,true)
F1.write (content)
F1.close
If filename1<> "" and Filename1<>filename then Fso.deletefile (filename1)
tempurl=url& "Foldername=" &fso. Getparentfoldername (filename)
Set fso=nothing
End If
Response. Redirect (Tempurl)
End Function

function FileNew ()
Filename=request. QueryString ("filename")
Content= ""
Fileform filename,content,filename1
End Function

function Fileedit ()
Filename=request. QueryString ("filename")
Filename1=request. QueryString ("filename")
Set Fso=server. CreateObject ("Scripting.FileSystemObject")
Set F1=fso.opentextfile (filename,1,true)
Content=server. HTMLEncode (F1.readall)
F1.close
Set fso=nothing
Fileform filename,content,filename1
End Function

function Fileform (filename,content,filename1)
%>
<table width= "100%" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
<form name= "Form1" method= "Post" action= "<%= url%>?action=savefile" >
<tr>
<td><input name= "filename1" type= "hidden" value= "<%= filename1%>" ><input name= "filename" type= " Text "value=" <%= filename%> "style=" width:100% "></td>
</tr>
<tr>
<td><textarea name= "Content" wrap= "VIRTUAL" style= "Width:100%;height:100%;font:arial,helvetica, Sans-serif; "onkeyup=" style.height=this.scrollheight; " ><%= content%></textarea></td>
</tr>
<tr>
<td><center><input type= "Submit" name= "Submit" value= "Save" style= "width:200" ><input "reset" "Name=" Submit2 "value=" Reset style= "width:200" ></center></td>
</tr>
</form>
</table>
<%
End Function
' Folder action function
function Delfolder ()
Foldername=request. QueryString ("foldername")
Set Fso=server. CreateObject ("Scripting.FileSystemObject")
tempurl=url& "Foldername=" &fso. Getparentfoldername (FolderName)
Fso.deletefolder (FolderName)
Set fso=nothing
Response. Redirect (Tempurl)
End Function

function Savefolder ()
Foldername=request. Form ("foldername")
Foldername1=request. Form ("foldername1")
Set Fso=server. CreateObject ("Scripting.FileSystemObject")
If foldername1= "" Then
Set F=fso.createfolder (foldername)
Else
Fso. MoveFolder Foldername1,foldername
End If
tempurl=url& "Foldername=" &f
Set fso=nothing
Response. Redirect (Tempurl)
End Function

function NewFolder ()
Foldername=request. QueryString ("foldername") & "\"
Formfolder foldername,foldername1
End Function

function Editfolder ()
Foldername=request. QueryString ("foldername")
Foldername1=request. QueryString ("foldername")
Formfolder foldername,foldername1
End Function

Function Formfolder (foldername,foldername1)
%>
<table width= "100%" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
<form name= "Form1" method= "Post" action= "<%= url%>?action= Savefolder ">
<tr><td><input name=" foldername1 "type=" hidden "value=" <%= foldername1%> " ><input name= "foldername" type= "text" value= "<%= foldername%>" style= "width:100%" ></td></tr >
<tr><td><center><input type= "Submit" name= "Submit" value= "Save" style= "width:200" > <input type= "reset" name= "Submit2" value= "reset" style= "width:200" ></center></td></tr>
</form>
</table>
<%
End Function

function upload ()
%>
<form action= "File.asp?action=saveupload" method= "post" enctype= "Multipart/form-data" name= "Form2" >
<div align= "center" > Remains to be completed
<input type= "File" name= "file" style= "width:80%" >
<input type= "Submit" name= "Submission" value= "submitted" >
</div>
</form>
<%
End Function

function Saveupload ()
' Yet to be realized
End Function

' Landing
function Chklogin ()
Password=request. Form ("password")
If password= "OK" then session ("login") = "Login"
If session ("login") <> "login" then login
End Function

function Login ()
%>
<form name= "Form1" method= "Post" action= "<%= url%>?action=chklogin" >
<center> Please enter the password: <input name= "password" type= "password" ><input type= "Submit" name= "Submit" value= "Landing" ></center>
</form>
<%
Response. End ()
End Function

function logout ()
Session. Abandon ()
Response. Redirect (URL)
End Function
%>




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.