ASP 使用FSO读取文件 可以按照文件名和修改日期排序

FSO读取文件功能十分强大

下面为mss.asp的代码

< body >
<%
' FSO读取文件
Function filelist(path1)
Dim oFSO, oCurrentFolder, oFolders, oFolder, oFiles, oFile ,path,pf
Set oFSO 
=  Server.CreateObject(  " Scripting.FileSystemObject "  )
path 
= path1
Set oCurrentFolder 
=  oFSO.GetFolder(path)
Set oFolders 
=  oCurrentFolder.SubFolders
Set oFiles   
=  oCurrentFolder.Files
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> "
next
   response.write 
" <hr> "
' 处理文件
Dim tmpDateStr,tmpNameStr,tmpDates,tmpNames,td,tn
Dim i,j,k,f,fil
tmpDateStr 
=   ""
tmpNameStr 
=   ""
For Each oFile 
in  oFiles
' 读取文件修改日期,并格式化(yyyy/MM/dd HH:mm:ss)
 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 )
 
' 读取文件到数组
tmpDateStr  =  tmpDateStr  &  f  &   " | "
tmpNameStr 
=  tmpNameStr  &  oFile.name  &   " | "
Next
tmpDates 
=  Split(tmpDateStr, " | " )
tmpNames 
=  Split(tmpNameStr, " | " )
=  UBound(tmpDates)
dim tmptotal()
if  k < 0  then 
  k
= 0
end 
if
redim tmptotal(k,
2 )
for  t = 0  to k - 1
    
  
if  isempty(request( " id " )) then
       tmptotal(t,
0 ) = tmpDates(t) 
       tmptotal(t,
1 ) = tmpNames(t)
  
else
    
if  request( " id " ) = 0  then
       tmptotal(t,
0 ) = tmpDates(t) 
       tmptotal(t,
1 ) = tmpNames(t) 
    
else
       tmptotal(t,
0 ) = tmpNames(t) 
       tmptotal(t,
1 ) = tmpDates(t) 
    end 
if
  end 
if
next
' 排序
For i = 0  To k
For j
= 0  To k
   If j
= k Then Exit For
   If tmptotal(j,
1 ) < tmptotal(j + 1 , 1 ) Then
    td 
=  tmptotal(j, 1 )
    tn 
=  tmptotal(j, 0 )
    tmptotal(j,
1 =  tmptotal(j + 1 , 1 )
    tmptotal(j,
0 =  tmptotal(j + 1 , 0 )
    tmptotal(j
+ 1 , 1 =  td
    tmptotal(j
+ 1 , 0 =  tn
   End If
Next
Next
  filelist
= tmptotal 
end Function
Dim fo
' 根据返回值决定文件路径
if  IsEmpty(Request( " path1 " ))then
  fo 
= " C:/Inet/sign "
else
  fo 
= Request( " path1 " )
end 
if  
' 列印文件路径
   response.write( " <font size=6>-- " & right(fo,len(fo) - 7 - instr(fo, " sign " )) & " </font><br><hr> " )
 
' 排除文件路径最后 ' / '
  dim st,g,fo1
  fo1
= ""
    st
= split(fo, " / " )
    g
= ubound(st) - 1
  
for  s = 0  to g
     fo1
= fo1  &  st(s) & " / "
  next
  
if  right(fo1, 1 ) = " / "  then
     fo1 
= left(fo1,len(fo1) - 1 )
   end 
if
   
' 允许访问到的文件夹最高层次
    if  fo1 <> " C:/Inet "  then
   response.write 
" <a href= "" mss.asp?path1= " & fo1 & """  target=_self>[To Parent Directory]</a> "
   end 
if
%>

 
< script   language = " javaScript "    type = " text/JavaScript " >    
  
<!--    
  
// 排序方式选择事件
  function   Showdiv(fo1)  
ExpandedBlockStart.gifContractedBlock.gif
{
       
if (di[0].checked)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
       di[
0].checked=true
           window.location.href
='mss.asp?id=0&path1='+fo1
         }

        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif         
{
    di[
1].checked=true
          window.location.href
='mss.asp?id=1&path1='+fo1
         }

}

  
// -->   
  ' server.urlencode用于处理有可能出现特殊符号
   </ script >   
    
< 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
    
</ p >
<%
' 列印文件
filearr  = filelist( "" & fo & "" )
For i
= 0  To ubound(filearr) - 1
    
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> " )
    
else  
      
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> " )
      
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> " )
    end 
if
    end 
if
         
Next
%>
</ body >

转载于:https://www.cnblogs.com/eugene512/archive/2009/02/02/1382624.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值