Enumerating Folder Properties

Microsoft® Windows® 2000 Scripting Guide

To retrieve the properties of a folder, a script must:

  1. Create an instance of the FileSystemObject.

  2. Use the GetFolder method to bind to an individual folder.

  3. Echo (or otherwise manipulate) the properties shown in Table 4.3.

When working with folder properties, note that the Files property and the Subfolders property both return collections rather than a single item. In addition, the Attributes property is returned as a bitmap value. A more detailed explanation of how to work with each of these properties is provided in subsequent sections of this chapter.

The script in Listing 4.12 uses the GetFolder method to bind to the folder C:\FSO and then echoes a number of properties for that folder.

Listing 4.12 Binding to a Specific Folder Using the GetFolder Method

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
Wscript.Echo "Date created: " & objFolder.DateCreated
Wscript.Echo "Date last accessed: " & objFolder.DateLastAccessed
Wscript.Echo "Date last modified: " & objFolder.DateLastModified
Wscript.Echo "Drive: " & objFolder.Drive
Wscript.Echo "Is root folder: " & objFolder.IsRootFolder
Wscript.Echo "Name: " & objFolder.Name
Wscript.Echo "Parent folder: " & objFolder.ParentFolder
Wscript.Echo "Path: " & objFolder.Path
Wscript.Echo "Short name: " & objFolder.ShortName
Wscript.Echo "Short path: " & objFolder.ShortPath
Wscript.Echo "Size: " & objFolder.Size
Wscript.Echo "Type: " & objFolder.Type

When this script runs under CScript, output similar to the following appears in the command window:

Date created: 2/7/2002 10:27:50 AM
Date last accessed: 2/13/2002 8:57:18 AM
Date last modified: 2/13/2002 8:57:18 AM
Drive: C:
Is root folder: False
Name: FSO
Parent folder: C:\
Path: C:\FSO
Short name: FSO
Short path: C:\FSO
Size: 0
Type: File Folder