Listing directories and files with ASP

Source: Internet
Author: User
Tags chr file info file size include
The following files are built in the same directory, IIS to determine the file operation components available, you can list files and directories with ASP, hehe
Welcome to my homepage http://skypavilion.yeah.net

----File Folder.inc-----
<%
Folderini= "C:\"
%>


----File Index.asp-----
<!--#Include file= "Folder.inc"-->
<title>FileSearch</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">

<frameset rows= "80,*" frameborder= "1" border= "1" framespacing= "1" cols= "*" >
<frame name= "Topframe" scrolling= "NO" src= "up.asp" >
<frame name= "MainFrame" src= "getinfo.asp?foldinfo=<%=folderini%>" >
</frameset>
<noframes><body bgcolor= "#FFFFFF" >

</body></noframes>



----File up.asp-----
<!--#Include file= "Folder.inc"-->
<style type= "Text/css" >
<!--
. ttl1_txt {font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
. cnt_txt {font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
A:link{color: #0000ff; Text-decoration:none}
a:visited {color: #0000ff; Text-decoration:none}
a:active {color: #33ccff; Text-decoration:underline}
a:hover {color: #33ccff; Text-decoration:underline}
body{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
tr{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
td{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt
-->
</style>

<table width= "780" border= "0" cellspacing= "1" cellpadding= "1" >
&LT;TR align= "center" >
&LT;TD align= "center" ><a href= "getinfo.asp?foldinfo=<%=folderini%>" target= "MainFrame" >list All Folder/file info</a>
</td>
</tr>
</table>



----File getinfo.asp-----
<!--#Include file= "Folder.inc"-->
<%foldinfo=trim (Request.QueryString ("Foldinfo"))%>
<title>GetInfo</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >
<!--
. ttl1_txt {font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
. cnt_txt {font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
A:link{color: #0000ff; Text-decoration:none}
a:visited {color: #0000ff; Text-decoration:none}
a:active {color: #33ccff; Text-decoration:underline}
a:hover {color: #33ccff; Text-decoration:underline}
body{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
tr{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
td{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt
-->
</style>
<script language= "JavaScript" >
function FileInfo (filenamecode,filesize,lastmodify) {
document.write (Filenamecode);
window.open ("fileinfo.asp?filename=" +filenamecode+ "&filesize=" +filesize+ "&
Lastmodify= "+lastmodify," "," Height=200,width=450,resizable=yes,scrollbars=yes,
Status=yes,toolbar=no,menubar=no,location=no ");
}
</Script>

<body bgcolor= "#FFFFFF" text= "#000000" >
<table width= "780" border= "0" cellspacing= "0" cellpadding= "0" >
<tr>
&LT;TD class= "Cnt_txt" > <font color= "#000000" >current folder:--</font><font color= "#FF7120" > <%=foldinfo%></font></td>
</tr>
<tr>
<td>
&LT;HR size= "1" >
</td>
</tr>
<tr>
<td>
<table width= "780" border= "0" cellspacing= "1" cellpadding= "1" >
<tr bgcolor= "#00CC00" >
&LT;TD width= "class=" "Cnt_txt" >folder name:</td>
&LT;TD width= "180" class= "Cnt_txt" >Size:</td>
&LT;TD width= "class=" "Cnt_txt" >LastModify:</td>
</tr>
</table>
</td>
</tr>
<tr>
&LT;TD align= "Right" class= "Cnt_txt" >
<%
Upfolder=left (Foldinfo,len (Foldinfo)-1)
Upfolder=left (Upfolder,instrrev (Upfolder, "\"))
If Foldinfo<>folderini Then
Response.Write ("<a href= ' getinfo.asp?foldinfo=" &upfolder& "' >parent folder</a>")
Else
Response.Write ("Parent Folder")
End If%>
</td>
</tr>
<tr>
&LT;TD class= "Cnt_txt" >
<% showfolderlist (foldinfo)%>
</td>
</tr>
<tr>
&LT;TD class= "Cnt_txt" >
<table width= "780" border= "0" cellspacing= "1" cellpadding= "1" >
<tr bgcolor= "#009999" >
&LT;TD width= ">file name:</td>"
&LT;TD width= "180" >Size:</td>
&LT;TD width= ">LastModify:</td>"
</tr>
</table>
</td>
</tr>
<tr>
&LT;TD class= "Cnt_txt" >
<% showfolderinfo (foldinfo)%>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>

<%
Sub showfolderlist (FOLDERSPEC)
Dim FS, F, F1, FC, S, schild,p,fsize
Set fs = CreateObject ("Scripting.FileSystemObject")
Set f = fs. GetFolder (FOLDERSPEC)
Set FC = F.subfolders
For each F1 in FC
s = f1.name
' s = S & vbCrLf
p = F1. DateLastModified
Fsize = F1. Size
schild=folderspec&s& "\"

Response.Write ("<table width= ' 780 ' border= ' 0 ' cellspacing= ' 1 ' cellpadding= ' 1 ' >")
Response.Write ("<tr>")
Response.Write ("<td width= ' bgcolor= ' #ECFFD9 ' ><font face= ' Wingdings ' font size= ' 3pt ' >0</font> <a href= ' getinfo.asp?foldinfo= ' &schild& ' > ' &s& ' </a></td> '
Response.Write ("<td width= ' 180 ' bgcolor= ' #ECFFD9 ' >" &fsize& "</td>")
Response.Write ("<td width= ' bgcolor= ' #ECFFD9 ' >" &p& "</td>")
Response.Write ("</tr>")
Response.Write ("</table>")

Next
End Sub

Sub Showfolderinfo (FOLDERSPC)
Set Myfileobject=server.createobject ("Scripting.FileSystemObject")


Set Myfolder=myfileobject.getfolder (FOLDERSPC)

For each thing in Myfolder.files
' Response.Write ("<br>" &thing)
' ===============get file information
Set Afile=myfileobject.getfile (Thing)

' ==========filename correct code
Filenamecode=afile.name
Filedetail=folderspc+filenamecode
Filedetail=replace (Filedetail, "\", "*s_p_l_i_t*")
Filesize=afile.size
Lastmodify=afile. DateLastModified

Response.Write ("<table width= ' 780 ' border= ' 0 ' cellspacing= ' 1 ' cellpadding= ' 1 ' >")
Response.Write ("<tr>")
Response.Write ("<td width= ' bgcolor= ' #f4f4ff ' ><font face= ' Wingdings ' font size= ' 3pt ' ><</font ><a href= "&AMP;CHR &" Javascript:fileinfo (' &filedetail& "', '" &filesize& ', ' "& lastmodify& "')" &AMP;CHR & ">" &filenamecode& "</a></td>")
Response.Write ("<td width= ' 180 ' bgcolor= ' #f4f4ff ' >" &filesize& "</td>")
Response.Write ("<td width= ' bgcolor= ' #f4f4ff ' >" &lastmodify& "</td>")
Response.Write ("</tr>")
Response.Write ("</table>")
Next
End Sub
%>
</body>


----File fileinfo.asp-----
<%
Filename=request.querystring ("filename")
Filename=replace (filename, "*s_p_l_i_t*", "\")
Filesize=request.querystring ("FileSize")
Lastmodify=request.querystring ("Lastmodify")
%>
<style type= "Text/css" >
<!--
. ttl1_txt {font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
. cnt_txt {font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
A:link{color: #0000ff; Text-decoration:none}
a:visited {color: #0000ff; Text-decoration:none}
a:active {color: #33ccff; Text-decoration:underline}
a:hover {color: #33ccff; Text-decoration:underline}
body{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
tr{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt}
td{font-family: "Verdana", "Arial", "Helvetica", "Sans-serif"; font-size:9pt
-->
</style>
<body>
<%
"Response.Write filename&" <br> "&filesize&" <br> "&lastmodify
%>
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 0 ">
<tr>
&LT;TD bgcolor= "#00CC00" colspan= "2" >current File info:</td>
</tr>
&LT;TR valign= "Top" >
&LT;TD width= ">file" location:</td>
&LT;TD width= "290" ><font color= "#990000" ><font face= ' Wingdings ' font size= ' 3pt ' ><</font> <b> <%=filename%></b></font></td>
</tr>
<tr>
&LT;TD colspan= "2" >
&LT;HR size= "1" >
</td>
</tr>
&LT;TR valign= "Top" >
&LT;TD height= "One" >file Size: </td>
&LT;TD height= "one" ><%=filesize%> bytes</td>
</tr>
<tr>
&LT;TD colspan= "2" >
&LT;HR size= "1" >
</td>
</tr>
&LT;TR valign= "Top" >
<td>lastmodify: </td>
<td><%=lastmodify%></td>
</tr>
<tr>
&LT;TD colspan= "2" >
&LT;HR size= "1" >
</td>
</tr>
<tr>
&LT;TD height= "A" colspan= "2" >
<p>please use appropriate application to Open this file.</p>
</td>
</tr>
<tr>
&LT;TD height= "align= Right" colspan= "2" ><a href= "Javascript:this.window.close ()" >close
Window</a></td>
</tr>
</table>
</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.