请教,关于相对路径读取jpg,gif文件名的代码
说明:我自己有一个网址比如http://www.abcdefg.com
在http://www.abcdefg.com/下有文件夹images,即:http://www.abcdefg.com/images
我想在打开index.asp时,就将images中的所有img,gif文件名读出到客端中去,以便可以使用javascript来切换图片的显示,
问题:
请大侠给一段一次性取得images目录下所有img,gif文件名的asp代码.
谢谢
------解决方案-------------------- '服务器端生成javascript脚本
<%
Response.Write " <script type= 'text/javascript '> " & chr(13) & "var images=new Array(); " & chr(13)
'建立正则表达式选择以.gif或.jpg、.jpeg、.bmp、.png结尾的文件
dim reg
set reg = new RegExp
reg.Pattern= "\.gif|jpg|jpeg|bmp|png$ "
Dim fso, f, folder,files
Set fso = CreateObject( "Scripting.FileSystemObject ")
Set folder = fso.GetFolder(server.MapPath( "/images "))
Set files = folder.Files
i=0
For Each f in files
if reg.test(f.name) then Response.Write "images[ " & i & "]= " " " & f.name & " " "; " & chr(13)
i=i+1
Next
Response.Write " </script> "
%>
<!--客户端调用-->
<script type= "text/javascript ">
for(var i=0;i <images.length;i++)
alert(images[i]);
</script>