SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Getting the list of files inside a directory by using FileSystemObject in ASP

By using FileSystemObject (FSO)we can list out all the files of a directory. Here we will be using server MapPath to map the virtual path to real path as used by file system object. After initiating the object we can instantiate the folder object. We will be using this folder object Files property to get all the files present within the folder.


Before this it is advisable to learn the FileSystemObject, Server MapPath to convert virtual path to real path before reading this.


In our example we have used the folder name my_folder which is inside the directory name t so the path of the folder is

http://mysite.com/t/my_folder/

Here is the code.

Dim objFSO, objFile, objFolder

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath("/t/my_folder"))

For Each objFile in objFolder.Files
Response.Write objFile.Name & "<br>"
Next
Set objFolder = Nothing
Set objFSO = Nothing

Displaying last updated date along with the file name

We can add the last modified date of the file by adding the DateLastModified property of the File object. This one line we will add inside the For Each Loop.

For Each objFile in objFolder.Files
Response.Write objFile.Name & " : "
Response.Write objFile.DateLastModified & "<br>"
Next




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
File Management