Show all Files in a Folder using the FileSystemObject
The example code below will display all the files that reside in the
folder 'images' located in the root folder.
<%
Dim oFilesys, oFolder, oFile
Set oFilesys= CreateObject("Scripting.FileSystemObject")
Set oFolder= oFilesys.GetFolder(Server.MapPath("/images/"))
For Each oFile in oFolder.Files
Response.write oFile.Name
Response.write "<br />"
Next
Set oFolder=Nothing
Set oFilesys=Nothing
%>
The example code below will display all the files that reside in the
folder in which this script resides.
<%
Dim oFilesys, oFolder, oFile, oFileItem
Dim sPathInfo, sPhysicalPath
sPathInfo=Request.ServerVariables("PATH_INFO")
sPhysicalPath=Server.MapPath(sPathInfo)
Set oFilesys= CreateObject("Scripting.FileSystemObject")
Set oFile=oFilesys.GetFile(sPhysicalPath)
Set oFolder= oFile.ParentFolder
For Each oFileItem in oFolder.Files
Response.write oFileItem.Name
Response.write "<br />"
Next
Set oFolder=Nothing
Set oFilesys=Nothing
%>
If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.
Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.
|