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
Further readings
Server.MapPath to convert virtual path to physical path of files and directory.
FileSystemObject:Checking file or folder exist by using File system object .
Getting the file name from full path of the current running script in ASP.
Getting the file extension and file name by using FSO
Deleting file by using DeleteFile in FSO
Getting the Last updating and creation date and time of a file.
Listing all files present inside a folder using FileSystemObject
Reading data from a text file using File System Object
Writing data to a text file using File System Object
Read & Writing data to a text file: Developing a page hit counter
Appending data to a text file: Storing emails in a text file
 
Scripts
PHP
JavaScript
All ASP Tutorials
File Management
MapPath
FileSystemObject
append
name
Updating Time
Listing all files
Reading file
Writing file
Read & Write
File type
Delete File
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.