Enumerating Folder Properties

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

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 

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net