ASP 使用FSO读取文件 可以按照文件名和修改日期排序
下面为mss.asp的代码
 <body>
<body> <%
<% 'FSO读取文件
'FSO读取文件 Function filelist(path1)
Function filelist(path1) Dim oFSO, oCurrentFolder, oFolders, oFolder, oFiles, oFile ,path,pf
Dim oFSO, oCurrentFolder, oFolders, oFolder, oFiles, oFile ,path,pf Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" ) path =path1
path =path1 Set oCurrentFolder = oFSO.GetFolder(path)
Set oCurrentFolder = oFSO.GetFolder(path) Set oFolders = oCurrentFolder.SubFolders
Set oFolders = oCurrentFolder.SubFolders Set oFiles   = oCurrentFolder.Files
Set oFiles   = oCurrentFolder.Files for each oFolders in oFolders
for each oFolders in oFolders '列印文件夹
'列印文件夹 response.write "<a href=""mss.asp?path1="&server.urlencode(path1)&""&server.urlencode("/")&""&server.urlencode(oFolders.name)&""" target=_self>"&oFolders.name&"</a><br>"
   response.write "<a href=""mss.asp?path1="&server.urlencode(path1)&""&server.urlencode("/")&""&server.urlencode(oFolders.name)&""" target=_self>"&oFolders.name&"</a><br>" next
next response.write "<hr>"
   response.write "<hr>" '处理文件
'处理文件 Dim tmpDateStr,tmpNameStr,tmpDates,tmpNames,td,tn
Dim tmpDateStr,tmpNameStr,tmpDates,tmpNames,td,tn Dim i,j,k,f,fil
Dim i,j,k,f,fil tmpDateStr = ""
tmpDateStr = "" tmpNameStr = ""
tmpNameStr = "" For Each oFile in oFiles
For Each oFile in oFiles '读取文件修改日期,并格式化(yyyy/MM/dd HH:mm:ss)
'读取文件修改日期,并格式化(yyyy/MM/dd HH:mm:ss) fil =oFile.DateLastModified
 fil =oFile.DateLastModified f =year(fil) &"/"&right("0"&month(fil),2)&"/"&right("0"&day(fil),2)&" "&right("0"&hour(fil),2)&":"&right("0"&minute(fil),2)&":"&right("0"&second(fil),2)
 f =year(fil) &"/"&right("0"&month(fil),2)&"/"&right("0"&day(fil),2)&" "&right("0"&hour(fil),2)&":"&right("0"&minute(fil),2)&":"&right("0"&second(fil),2) '读取文件到数组
 '读取文件到数组 tmpDateStr = tmpDateStr & f & "|"
tmpDateStr = tmpDateStr & f & "|" tmpNameStr = tmpNameStr & oFile.name & "|"
tmpNameStr = tmpNameStr & oFile.name & "|" Next
Next tmpDates = Split(tmpDateStr,"|")
tmpDates = Split(tmpDateStr,"|") tmpNames = Split(tmpNameStr,"|")
tmpNames = Split(tmpNameStr,"|") k = UBound(tmpDates)
k = UBound(tmpDates) dim tmptotal()
dim tmptotal() if k<0 then
if k<0 then  k=0
  k=0 end if
end if redim tmptotal(k,2)
redim tmptotal(k,2) for t=0 to k-1
for t=0 to k-1 
     if isempty(request("id")) then
  if isempty(request("id")) then tmptotal(t,0)=tmpDates(t)
       tmptotal(t,0)=tmpDates(t)  tmptotal(t,1)=tmpNames(t)
       tmptotal(t,1)=tmpNames(t) else
  else if request("id")=0 then
    if request("id")=0 then tmptotal(t,0)=tmpDates(t)
       tmptotal(t,0)=tmpDates(t)  tmptotal(t,1)=tmpNames(t)
       tmptotal(t,1)=tmpNames(t)  else
    else tmptotal(t,0)=tmpNames(t)
       tmptotal(t,0)=tmpNames(t)  tmptotal(t,1)=tmpDates(t)
       tmptotal(t,1)=tmpDates(t)  end if
    end if end if
  end if next
next '排序
'排序 For i=0 To k
For i=0 To k For j=0 To k
For j=0 To k If j=k Then Exit For
   If j=k Then Exit For If tmptotal(j,1)<tmptotal(j+1,1) Then
   If tmptotal(j,1)<tmptotal(j+1,1) Then td = tmptotal(j,1)
    td = tmptotal(j,1) tn = tmptotal(j,0)
    tn = tmptotal(j,0) tmptotal(j,1) = tmptotal(j+1,1)
    tmptotal(j,1) = tmptotal(j+1,1) tmptotal(j,0) = tmptotal(j+1,0)
    tmptotal(j,0) = tmptotal(j+1,0) tmptotal(j+1,1) = td
    tmptotal(j+1,1) = td tmptotal(j+1,0) = tn
    tmptotal(j+1,0) = tn End If
   End If Next
Next Next
Next filelist=tmptotal
  filelist=tmptotal  end Function
end Function Dim fo
Dim fo '根据返回值决定文件路径
'根据返回值决定文件路径 if IsEmpty(Request("path1"))then
if IsEmpty(Request("path1"))then fo ="C:/Inet/sign"
  fo ="C:/Inet/sign" else
else fo =Request("path1")
  fo =Request("path1") end if
end if  '列印文件路径
'列印文件路径 response.write("<font size=6>--"&right(fo,len(fo)-7-instr(fo,"sign"))&"</font><br><hr>")
   response.write("<font size=6>--"&right(fo,len(fo)-7-instr(fo,"sign"))&"</font><br><hr>") '排除文件路径最后'/'
 '排除文件路径最后'/' dim st,g,fo1
  dim st,g,fo1 fo1=""
  fo1="" st=split(fo,"/")
    st=split(fo,"/") g=ubound(st)-1
    g=ubound(st)-1 for s=0 to g
  for s=0 to g fo1=fo1 & st(s)&"/"
     fo1=fo1 & st(s)&"/" next
  next if right(fo1,1)="/" then
  if right(fo1,1)="/" then fo1 =left(fo1,len(fo1)-1)
     fo1 =left(fo1,len(fo1)-1) end if
   end if '允许访问到的文件夹最高层次
   '允许访问到的文件夹最高层次 if fo1<>"C:/Inet" then
   if fo1<>"C:/Inet" then response.write "<a href=""mss.asp?path1="&fo1&""" target=_self>[To Parent Directory]</a>"
   response.write "<a href=""mss.asp?path1="&fo1&""" target=_self>[To Parent Directory]</a>" end if
   end if %>
%>
 <script   language="javaScript"   type="text/JavaScript">
 <script   language="javaScript"   type="text/JavaScript">    <!--
  <!--    //排序方式选择事件
  //排序方式选择事件 function   Showdiv(fo1)
  function   Showdiv(fo1)   {
{ if (di[0].checked)
       if (di[0].checked) {
        { di[0].checked=true
       di[0].checked=true window.location.href='mss.asp?id=0&path1='+fo1
           window.location.href='mss.asp?id=0&path1='+fo1 }
         } else
        else {
         { di[1].checked=true
    di[1].checked=true window.location.href='mss.asp?id=1&path1='+fo1
          window.location.href='mss.asp?id=1&path1='+fo1 }
         } }
} //-->
  //-->    'server.urlencode用于处理有可能出现特殊符号
 'server.urlencode用于处理有可能出现特殊符号 </script>
  </script>   <p align="left">Desc:
    <p align="left">Desc:   <INPUT id="name1" name="di" type="radio" value="0" <%if isempty(request("id")) then response.write "checked=""checked""" else if request("id")=0 then response.write"checked=""checked""" end if end if %> onclick="return Showdiv('<%=server.urlencode(fo)%>')" >By Name<INPUT id="date1" name="di" type="radio" value="1" <%if isempty(request("id")) then response.write""  else if request("id")=1 then response.write"checked=""checked""" end if end if %> onclick="return Showdiv('<%=server.urlencode(fo)%>')">By Date
           <INPUT id="name1" name="di" type="radio" value="0" <%if isempty(request("id")) then response.write "checked=""checked""" else if request("id")=0 then response.write"checked=""checked""" end if end if %> onclick="return Showdiv('<%=server.urlencode(fo)%>')" >By Name<INPUT id="date1" name="di" type="radio" value="1" <%if isempty(request("id")) then response.write""  else if request("id")=1 then response.write"checked=""checked""" end if end if %> onclick="return Showdiv('<%=server.urlencode(fo)%>')">By Date </p>
    </p> <%
<% '列印文件
'列印文件 filearr =filelist(""&fo&"")
filearr =filelist(""&fo&"") For i=0 To ubound(filearr)-1
For i=0 To ubound(filearr)-1 if isempty(request("id")) then
    if isempty(request("id")) then Response.Write(filearr(i,0) & " -- <a href=""download.asp?filename="&server.urlencode(fo)&""&server.urlencode("/")&""&server.urlencode(filearr(i,1))&""">"&filearr(i,1)&"</a><br>")
      Response.Write(filearr(i,0) & " -- <a href=""download.asp?filename="&server.urlencode(fo)&""&server.urlencode("/")&""&server.urlencode(filearr(i,1))&""">"&filearr(i,1)&"</a><br>") else
    else  if request("id")=0 then
      if request("id")=0 then Response.Write(filearr(i,0) & " -- <a href=""download.asp?filename="&server.urlencode(fo)&""&server.urlencode("/")&""&server.urlencode(filearr(i,1))&""">"&filearr(i,1)&"</a><br>")
      Response.Write(filearr(i,0) & " -- <a href=""download.asp?filename="&server.urlencode(fo)&""&server.urlencode("/")&""&server.urlencode(filearr(i,1))&""">"&filearr(i,1)&"</a><br>") else
      else Response.Write(filearr(i,1) & " -- <a href=""download.asp?filename="&server.urlencode(fo)&""&server.urlencode("/")&""&server.urlencode(filearr(i,0))&""">"&filearr(i,0)&"</a><br>")
         Response.Write(filearr(i,1) & " -- <a href=""download.asp?filename="&server.urlencode(fo)&""&server.urlencode("/")&""&server.urlencode(filearr(i,0))&""">"&filearr(i,0)&"</a><br>") end if
    end if end if
    end if 
          Next
Next %>
%> </body>
</body> 
                     
                    
                 
                    
                 
 
        

 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号