用ASP 取得目录下的文件名

时间:2021-05-23 12:24:15
 <%@ Language=VBScript %>
<%
'================================================================
'函数名称:FileList
'函数功能:列出目录下所有文件
'主要参数说明:
'1——FolderUrl 虚拟路径 不可为空
'2----FileExName 文件扩展名
'函数返回值:收文记录
'================================================================
Function FileList(FolderUrl,FileExName)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set folder=fso.GetFolder(Server.MapPath(Trim(FolderUrl)))
Set file=folder.Files
FileList=""
For Each FileName in file
If Trim(FileExName)<>"" Then
If InStr(Trim(FileExName),Trim(Mid(FileName.Name,InStr(FileName.Name,".")+1,len(FileName.Name))))>0 Then
'FileList=FileList&FileName.Name&"<br>"
    FileList=FileList&"<a href='"&FolderUrl&"/"&FileName.Name&"'>"&FileName.Name&"</a><br>"
End If
Else
   FileList=FileList&"<a href='"&FolderUrl&"/"&FileName.Name&"'>"&FileName.Name&"</a><br>"
'FileList=FileList&FileName.Name&"<br>"
End If
Next
Set file=Nothing
Set folder=Nothing
Set fso=Nothing
End Function
Response.Write FileList("/你的虚拟路径","gif,GIF,jpg,JPG,rar,RAR,zip,ZIP")
%>