Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

asp

What are folder objects in ASP?

Khizar Hayat Saani

We can use the Folder object in ASP to access all information regarding a specific folder. The object contains collections, properties, and methods that we can use to return relevant information.

To access the properties of a Folder object, we must first obtain a Folder object.

Obtaining a Folder object

We obtain a Folder object using the GetFolder() method of a FileSystemObject.

We can instantiate a Folder object as follows:

'Declare variables
Dim file_sys, folder_obj, message

'Define FileSystemObject
Set file_sys = Server.CreateObject("Scripting.FileSystemObject")

'Obtain Folder object
Set folder_obj = file_sys.GetFolder("c:\test")

Collections, properties, and methods

The Folder object contains collections, properties, and methods to add to its functionality.

Collections

The Folder object contains the following collections:

  1. Files: Returns a collection of all the files in a specific folder.

  2. SubFolders: Returns a collection of Folder objects within a specific Folder.

Dim file_sys, folder_obj, file
Set file_sys = Server.CreateObject("Scripting.FileSystemObject")
Set folder_obj = file_sys.GetFolder("c:\test\")

for each file in folder_obj.files
  'Print the name of all files in the Folder
  Response.write(file.Name & "<br>")
next

Set folder_obj = nothing
Set file_sys = nothing

Output

file1.txt
file2.txt
file3.txt

Properties

There are several properties associated with a Folder object.

Some of these include:

  • Attributes: Sets or returns the attributes of a folder.

  • DateCreated: Returns the date and time when a specific folder was created.

  • ParentFolder: Returns the parent folder of a folder.

  • Name: Sets or returns the name of a folder.

  • Size: returns the size of a folder.

'Declare variables
Dim file_sys, folder_obj, message

'Define FileSystemObject
Set file_sys = Server.CreateObject("Scripting.FileSystemObject")

'Obtain Folder object
Set 
folder_obj = file_sys.GetFolder("c:\test")

'Creating response message
message = folder_obj.DateCreated
Response.Write("Folder created: " & s)

'Deallocating
set folder_obj = nothing
set file_sys = nothing

Ouput

Folder created: 08/10/2012 10:01:26 AM

Methods

The Folder object also contains some methods. These methods are summarized in the table below:

Method

Description

Move

Moves a folder from one place to another

CreateTextFile

Creates a text file in the given folder and returns a TextStream object for writing data to the file

AddFolders

Adds a new folder to a Folder collection

Copy

Copies a folder from one place to another

Delete

Deletes the specified folder

Dim file_sys

Set file_sys = Server.CreateObject("Scripting.FileSystemObject")

file_sys.MoveFolder "source","destination"

Set file_sys = nothing

RELATED TAGS

asp

CONTRIBUTOR

Khizar Hayat Saani
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring