Skip to main content

Folder object

Provides access to all the properties of a folder.

Examples

The following code illustrates how to obtain a Folder object and how to return one of its properties.

Sub ShowFolderInfo(folderspec As String)
    Dim fs As Object, f As Object, msg As String
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    msg = "Folder Name: " & f.Name
    msg = msg & vbCrLf
    msg = msg & "DateCreated: " & f.DateCreated
    MsgBox msg
End Sub

Run the following code in the Immediate Window to test this macro:

ShowFolderInfo("d:\TestFolder")

Result:

Collections

Collection Description
Files Returns a collection of all the files in a specified folder.
SubFolders Collection of all Folder objects contained within a Folder object.

Methods

Method Description
AddFolders Adds a new Folder to a Folders collection.
Copy Copies a specified folder from one location to another.
CreateTextFile Creates a new text file in the specified folder and returns a TextStream object to access the file.
Delete Deletes a specified folder.
Move Moves a specified folder from one location to another.

Properties

Property Description
Attributes Sets or returns the attributes of a specified folder.
DateCreated Returns the date and time when a specified folder was created.
DateLastAccessed Returns the date and time when a specified folder was last accessed.
DateLastModified Returns the date and time when a specified folder was last modified.
Drive Returns the drive letter of the drive where the specified folder resides.
Files Returns a Files collection consisting of all File objects contained in the specified folder, including those with hidden and system file attributes set.
IsRootFolder Returns True if a folder is the root folder and False if not.
Name Sets or returns the name of a specified folder.
ParentFolder Returns the parent folder of a specified folder.
Path Returns the path for a specified folder.
ShortName Returns the short name of a specified folder (the 8.3 naming convention).
ShortPath Returns the short path of a specified folder (the 8.3 naming convention).
Size Returns the size of a specified folder.
SubFolders Returns a Folders collection consisting of all folders contained in a specified folder, including those with Hidden and System file attributes set.
Type Returns the type of a specified folder.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>