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

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

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

<%
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>"
%>

你可能感兴趣的:(文件)