当前位置:asp编程网>技术教程>Asp教程>  正文

asp实现查找指定目录下的某一扩展名的文件

2009-02-08 09:02:39   来源:aspprogram.cn    作者:佚名   浏览量:2206   收藏

实现的原理是使用fso和递归实现查找指定目录下某一扩展名的文件
< %
'===========================================
' 函数功能:asp实现查找指定目录下的某一扩展名的文件
' 作    者:wangsdong
' 网    站: http://www.aspprogram.cn
' 参数意义:path为相对路径,当前目录使用“.”,上级目录“..”,
'                下级目录直接输入文件夹名,style为扩展名:如asp,mdb等
' 文章为作者原创,转载请注明文章出处、保留作者
' 信息,谢谢支持!
'===========================================
Function findfile(path,style)
'创建一个FileSystemObject对象的事例
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
'创建一个Folder对象
foldername=server.mappath(path)
Set MyFolder=MyFileObject.GetFolder(foldername)
'循环显示其中文件夹
For Each thing in MyFolder.subfolders
  if MyFileObject.folderExists(thing) then            '判断folder文件夹是否存在
     t2=thing   
      folder=Replace(thing,foldername&"\","")
   t=path&"/"&folder
   Call findfile(t,style)
  end if
Next
'循环显示其中文件
For Each thing in MyFolder.Files
  if MyFileObject.FileExists(thing) then            '判断folder文件夹是否存在
    t2=thing
 m=Split(thing,"\")
 filename=m(UBound(m))
 t0=Split(filename,".")(1)
 If t0=style Then
   response.write thing&"< BR>"
 End if
  end if
Next
End Function

Call findfile(".","mdb")
% >



关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网