WSH » WshSpecialFolders » Item

Syntax:
object[.Item] (lngIndex)
lngIndex
Receives the index of a specific element to be returned.

The Item method is the default method of the WshSpecialFolders object. It takes a single argument of type Long, and returns the element in the collection at the specified position. Indexing starts at zero. If there is no element at the requested index, a "Subscript out of range" error is generated. A key string can also be used to access the items in the WshSpecialFolders. If key string is an invalid key, a NULL will be returned.

The following is the list of available special folders on various Windows OS. (Note: not all of the following special folders are available to all flavors of Windows).

  • AllUsersDesktop
  • AllUsersStartMenu
  • AllUsersPrograms
  • AllUsersStartup
  • Desktop
  • Favorites
  • Fonts
  • MyDocuments
  • NetHood
  • PrintHood
  • Programs
  • Recent
  • SendTo
  • StartMenu
  • Startup
  • Templates

Examples

Code:
WScript.Echo "The path to Desktop is: ", WshSpecialFolder("Desktop")
WScript.Echo "The path to Desktop is: ", WshSpecialFolder.Item("Desktop")
Output:
C:\WINNT\Profile\User\Desktop
C:\WINNT\Profile\User\Desktop
Explanation:

This VBScript code displays the path to the special folder "Desktop". The example also illustrates both forms of syntax that can be used to call the default Item method.

Language(s): VBScript