遍历指写盘符下的所有文件

很多以前写的,可以遍历指写盘符下的所有文件,以目录的形式显示出来,且文件夹用红色粗体显示.

最后还统计总文件的个数,所占空间等等.

 <%
dim Check_T
Check_T=0
dim Tab_Symbol
Tab_Symbol="&nbsp;&nbsp;&nbsp; |"
dim AFiles,AFolder,AFileSize
AFiles=0
AFolder=0
AFileSize=0
Function PL(path) '该函数打印指定驱动器下的所有文件及所有文件夹下的内容
  dim objFolder
  dim objFolders
  dim objSubFolders
  dim objSubFolder
  dim objFiles
  dim objFile
  dim FSO 
  set FSO=server.createobject("scripting.FileSystemObject")
  on error resume next
  set objFolders=FSO.getFolder(path)'建立文件夹对象
  set objSubFolders=objFolders.subFolders  '建立子文件夹对象
  'response.write "<font color=red>"&path&"</font><br>"
  '打印盘符根目录下的文件
  'response.write "根目录下:<br>"
  Check_T=Check_T+1
  AFolder=AFolder+1
  'response.write "<font color=red><b>"&Check_T&"</b></font>"
  if Check_T=1 then
 response.write "<font color=red>根目录下:</font><br>"
 response.write "|---<br>"
   for each objFile in objFolders.files
       response.write Tab_Symbol&"-"&objFile.name&"<br>"
  AFiles=AFiles+1
  AFileSize=AFileSize+objFile.size
   next
  end if
  '打印盘符根目录下的子目录及子目录下的文件

  for each objSubFolder in objSubFolders
   if objSubFolder.name="_vti_cnf" then
   else
    if Check_T>1 then
     Tab_Symbol="&nbsp;&nbsp;&nbsp;&nbsp;"&Tab_Symbol
    end if
    nowpath=path+"/"+objSubFolder.name
    nowpathT=split(nowpath,"/")
    'if then
 'Tab_Symbol=
    'end if
    response.write Tab_Symbol&"---<font color=red><b>"&nowpathT(ubound(nowpathT))&"</b></font><br>"
    set objFiles=objSubFolder.files
    for each objFile in objFiles
      AFiles=AFiles+1
      AFileSize=AFileSize+objFile.size  
      response.write "&nbsp;&nbsp;&nbsp; "&Tab_Symbol&"-"&objFile.name&"<br>"
    next
    PL(nowpath)
   end if
  next
 
  set objSubFolders=nothing
  set objFolders=nothing
  set FSO=nothing
  Tab_Symbol="&nbsp;&nbsp;&nbsp; |"
  'response.write "<font color=red><b>"&Check_T&"</b></font>"
end Function
Function PLADrivers()    '打印硬盘中所有的文件
  dim FSOD
  dim driver
  set FSOD=server.createobject("scripting.FileSystemObject")
  for each driver in FSOD.drives
    response.write "<font color=blue>当前盘为:"&driver&"</font><p>"
    call PL(driver)
  next
end Function
'call PLADrivers()
dim My_Path
My_Path=server.mappath("../all")
call PL(My_Path)
response.write "<p><font color=red><b>共有目录:"&AFolder&"个 文件:"&AFiles&"个 总共占空间为:"&Left(CStr(AFileSize/(1024*1024)),4)&"M</b></font><p>"
%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值