Read all filenames from folder using ASP Classic Vbscript
Sometimes you require to get a list of all the files name from a folder, I was thinking how it can be implemented, the solution is to used the interface and write a script in VBScript. There is a sample script which is build in ASP Vbscript will get the list of files on a Folder.
function GetFiles(pFolder, pPattern)
dim Filelist
set Filelist = Server.CreateObject("SCRIPTING.DICTIONARY")
dim Regex
set Regex = new RegExp
Regex.IgnoreCase = true
Regex.Pattern = pPattern
dim Fso
set Fso = Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
dim Folder
set Folder = Fso.GetFolder(Server.MapPath(pFolder))
dim File
for each File in Folder.Files
if Regex.Test(File.Name) then
Filelist.add File.Name, Array(File.Type, File.Size, File.DateLastModified)
end if
next
set File = nothing
set Folder = nothing
set Fso = nothing
set Regex = nothing
set GetFiles = Filelist
end function
dim Files
set Files = GetFiles("agencies", "\.(asp|gif|jpg|jpeg|png|tif)$")
if Files.Count = 0 then
Response.write "There are no images to display. "
end if
dim Filename
for each Filename in Files
Response.write Filename
Response.write Files(Filename)(0)
Response.write Files(Filename)(1)
Response.writeFiles(Filename)(2)
next