ASP file Operations--listing directories and files
Last Update:2017-02-28
Source: Internet
Author: User
The following files are built in the same directory, IIS to determine the file operation components available, you can use ASP listing files and directories, 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" >
<TR align= "center" >
<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>
<TD class= "Cnt_txt" > <font color= "#000000" >current folder:--</font><font color= "#FF7120" > <%=foldinfo%></font></td>
</tr>
<tr>
<td>
<HR size= "1" >
</td>
</tr>
<tr>
<td>
<table width= "780" border= "0" cellspacing= "1" cellpadding= "1" >
<tr bgcolor= "#00CC00" >
<TD width= "class=" "Cnt_txt" >folder name:</td>
<TD width= "180" class= "Cnt_txt" >Size:</td>
<TD width= "class=" "Cnt_txt" >LastModify:</td>
</tr>
</table>
</td>
</tr>
<tr>
<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>
<TD class= "Cnt_txt" >
<% showfolderlist (foldinfo)%>
</td>
</tr>
<tr>
<TD class= "Cnt_txt" >
<table width= "780" border= "0" cellspacing= "1" cellpadding= "1" >
<tr bgcolor= "#009999" >
<TD width= ">file name:</td>"
<TD width= "180" >Size:</td>
<TD width= ">LastModify:</td>"
</tr>
</table>
</td>
</tr>
<tr>
<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= "&CHR &" Javascript:fileinfo (' &filedetail& "', '" &filesize& ', ' "& lastmodify& "')" &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>
<TD bgcolor= "#00CC00" colspan= "2" >current File info:</td>
</tr>
<TR valign= "Top" >
<TD width= ">file" location:</td>
<TD width= "290" ><font color= "#990000" ><font face= ' Wingdings ' font size= ' 3pt ' ><</font> <b> <%=filename%></b></font></td>
</tr>
<tr>
<TD colspan= "2" >
<HR size= "1" >
</td>
</tr>
<TR valign= "Top" >
<TD height= "One" >file Size: </td>
<TD height= "one" ><%=filesize%> bytes</td>
</tr>
<tr>
<TD colspan= "2" >
<HR size= "1" >
</td>
</tr>
<TR valign= "Top" >
<td>lastmodify: </td>
<td><%=lastmodify%></td>
</tr>
<tr>
<TD colspan= "2" >
<HR size= "1" >
</td>
</tr>
<tr>
<TD height= "A" colspan= "2" >
<p>please use appropriate application to Open this file.</p>
</td>
</tr>
<tr>
<TD height= "align= Right" colspan= "2" ><a href= "Javascript:this.window.close ()" >close
Window</a></td>
</tr>
</table>
</body>