ASP文件操作--列出目录及文件

把以下文件建在同一目录,IIS中确定文件操作组件可用,即可用ASP列出文件和目录了,呵呵欢迎光临我的主页 http://skypavilion.yeah.net

----文件folder.inc-----
<%
folderini="c:\"
%>

----文件index.asp-----
<!--#Include file="folder.inc"-->
<html>
<head>
<title>FileSearch</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<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>
</html>

----文件up.asp-----
<!--#Include file="folder.inc"-->
<html><title>Up</title>
<head>
<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>

</head>
<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>
</html>

----文件getinfo.asp-----
<!--#Include file="folder.inc"-->
<%foldinfo=trim(Request.Querystring("foldinfo"))%>
<html>
<head>
<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>
</head>

<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="300" class="cnt_txt">Folder Name:</td>
          <td width="180" class="cnt_txt">Size:</td>
          <td width="300" 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="300">File Name:</td>
          <td width="180">Size:</td>
          <td width="300">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='300' 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='300' 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='300' bgcolor='#f4f4ff'><font face='Wingdings' font size='3pt'><</font><a href="&chr(34)&"javascript:fileinfo('"&filedetail&"','"&filesize&"','"&lastmodify&"')"&chr(34)&">"&filenamecode&"</a></td>")
Response.write("<td width='180' bgcolor='#f4f4ff'>"&filesize&"</td>")
Response.write("<td width='300' bgcolor='#f4f4ff'>"&lastmodify&"</td>")
Response.write("</tr>")
Response.write("</table>")
Next
End sub
%>
</body>
</html>

----文件fileinfo.asp-----
<%
filename=Request.QueryString("filename")
filename=replace(filename,"*s_p_l_i_t*","\")
filesize=Request.QueryString("filesize")
lastmodify=Request.QueryString("lastmodify")
%>
<html>
<head>
<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>
</head>
<body>
<%
'Response.write filename&"<br>"&filesize&"<br>"&lastmodify
%>
<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#00CC00" colspan="2">Current File Info:</td>
  </tr>
  <tr valign="top">
    <td width="110">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="11">File Size: </td>
    <td height="11"><%=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="18" colspan="2">
      <p>Please Use appropriate Application to Open this File.</p>
    </td>
  </tr>
  <tr>
    <td height="13" align="right" colspan="2"><a href="javascript:this.window.close()">Close
      Window</a></td>
  </tr>
</table>
</body>
</html>

时间: 2024-12-03 14:25:51

ASP文件操作--列出目录及文件的相关文章

python文件操作之目录遍历实例分析

  本文实例讲述了python文件操作之目录遍历的方法.分享给大家供大家参考.具体分析如下: Python的os模块,包含了普遍的操作系统功能,这里主要学习与路径相关的函数: os.listdir(dirname):列出dirname下的目录和文件 os.getcwd():获得当前工作目录 os.curdir:返回当前目录('.') os.chdir(dirname):改变工作目录到dirname os.path.isdir(name):判断name是不是一个目录,name不是目录就返回fals

python连接远程ftp服务器并列出目录下文件的方法

  本文实例讲述了python连接远程ftp服务器并列出目录下文件的方法.分享给大家供大家参考.具体如下: 这段python代码用到了pysftp模块,使用sftp协议,对数据进行加密传输   1 2 3 4 5 6 7 8 9 10 import pysftp srv = pysftp.Connection(host="your_FTP_server", username="your_username",password="your_password&q

PHP目录文件操作函数目录操作详谈

目录,文件操作详谈-php   ● 写文件 和读取文件的方式一样,先看看是不是能写: <?php $file = ''dirlist.php'';if (is_writable($file) == false) {        die("我是鸡毛,我不能");}?> 能写了的话可以使用file_put_contents函数写入: <?php$file = ''dirlist.php'';if (is_writable($file) == false) {      

python连接远程ftp服务器并列出目录下文件的方法_python

本文实例讲述了python连接远程ftp服务器并列出目录下文件的方法.分享给大家供大家参考.具体如下: 这段python代码用到了pysftp模块,使用sftp协议,对数据进行加密传输 import pysftp srv = pysftp.Connection(host="your_FTP_server", username="your_username",password="your_password") # Get the directory

数字后缀文件名排序-多文件操作,数字后缀文件排序

问题描述 多文件操作,数字后缀文件排序 文件排列后是这样的 文件夹 name=jsp2html.log name=jsp2html.log.1 name=jsp2html.log.10 name=jsp2html.log.11 name=jsp2html.log.12 name=jsp2html.log.13 name=jsp2html.log.14 name=jsp2html.log.15 name=jsp2html.log.16 name=jsp2html.log.17 name=jsp2h

重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作

原文:重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作 [源码下载] 重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 文件系统 Applicatio

用ASP列出目录及文件

把以下文件建在同一目录,IIS中确定文件操作组件可用,即可用ASP列出文件和目录了,呵呵欢迎光临我的主页 http://skypavilion.yeah.net ----文件folder.inc-----<%folderini="c:\"%> ----文件index.asp-----<!--#Include file="folder.inc"--><html><head><title>FileSearch&

asp删除文件目录及目录所有文件代码

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-tra

PHP常用技术文之文件操作和目录操作总结

 一.基本文件的操作 文件的基本操作有:文件判断.目录判断.文件大小.读写性判断.存在性判断及文件时间等 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69