File SystemObject GetSpecial Folder Method VB

Syntax oFileSysObj .GetSpecialFolder( SpecialFolder) oFileSysObj

Use: Required

Data Type: FileSystemObject object

Any object variable returning a FileSystemObject object.

SpecialFolder Use: Required

Data Type: Special folder constant A value specifying one of three special system folders.

Return Value

A Folder object Description

Returns a reference to a Folder object of one of the three special system folders: System, Temporary, and Windows.

Rules at a Glance

SpecialFolder can be one of the following special folder constants:

Constant

Value

Description

SystemFolder

1

The Windows system folder (/windows/system or /windows/system32)

TemporaryFolder

2

The folder that stores temporary files (../windows/temp)

WindowsFolder

0

The root folder of the Windows system folder tree (/windows or /winnt)

Programming Tips & Gotchas

• This method is a great boon for VB programmers who don't want to get involved with the Windows API, which, in the past, is how you had to determine a path to one of the special folders.

• You can use the Set statement to assign the Folder object reference to a local object variable. However, if you're interested only in retrieving the path to the special folder, you can do it with a statement like the following:

sPath = oFileSys.GetSpecialFolder(iFolderConst)

sPath = oFileSys.GetSpecialFolder(iFolderConst).Path

The first statement works because the Path property is the Folder object's default property. Since the assignment isn't to an object variable, it's the

302 Chapter 7- The Language Reference default property's value, rather than the object reference, that is assigned to sPath.

0 0

Post a comment