ASP中如何获取指定文件夹下所有文件名称,请看下面获取示例代码。
<html> <head> </head> <body> <% dim myfilename() redim myfilename(0) set fs=Server.CreateObject("Scripting.FileSystemObject") sub showfile(thefolder) set fd=fs.getfolder(thefolder) for each myfile in fd.files i=ubound(myfilename) myfilename(i)=fd.path & "\" & myfile.name redim Preserve myfilename(i+1) next for each myfolder in fd.SubFolders '递归记录其它文件夹的文件 call showfile(fd.path & "\" & myfolder.name) next end sub thefolder="e:\lzweb" '在此指定要搜索的文件夹绝对路径,要确定匿名用户有访问的权限,否则会出错 call showfile(thefolder) '过程调用后,查到的文件名包括路径名保存在myfilename数组, '共ubound(myfilename)个,下标分布在0至ubound(myfilename)-1; '以下示例把找到文件显示出来 response.write("共找到" & ubound(myfilename) & "个文件<br>") for i=0 to ubound(myfilename)-1 response.write(i+1 & "--" & myfilename(i) & "<br>") next %> </body> </html>
声明:如需转载,请注明来源于www.webym.net并保留原文链接:http://www.webym.net/jiaocheng/910.html