Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

October 25, 2000 12:00 AM

Understanding VBScript: The Shell Object Model’s Folder and FolderItem Objects

Windows IT Pro
InstantDoc ID #15847
Rating: (0)
Downloads
15847.zip

In Windows 95 and later, the file system is just one possible place to store and search for information. As a result, the pre-Win95 hierarchy of files and directories no longer adequately describes the possible objects that you can now access in Windows. New types of folders such as the Recycle Bin, My Documents, and Printers forced the adoption of a new programming interface. In this new programming interface, Folder objects represent Windows shell folders that contain files or references to other types of objects. (The Folder object in the Windows Shell object model isn't related to the Folder object in the File System Object—FSO—object model. The objects simply share the same name.) Because files no longer solely define a folder's content, more general objects called FolderItem objects represent the items in a folder. A FolderItem can be a file or a chunk of data that represents, for example, a printer or deleted file. A collection called FolderItems represents all the FolderItem objects in a folder.

Because a folder is essentially a container that holds data, you can use a common set of methods and properties (i.e., the Folder object's methods and properties) to access many different types of objects. As a container of data, a folder is able to describe itself in terms of name, title, path, and content. The content can vary widely depending on a folder's particular role. For this reason, each folder implements a special functionality: the ability to enumerate child items (i.e., FolderItem objects). Each child item, in turn, has fixed properties and methods that you use to manipulate it. Here's a look at how you use the methods and properties of the Folder and FolderItem objects.

Getting Started: Creating an Instance of the Folder Object
You typically don't create instances of the Folder object directly. Instead, use the NameSpace method with a pathname or virtual folder ID to create instances. Listing 1 shows the NameSpace method in action. In this code, the myFolder variable is of type Folder. (For information about how the NameSpace method works, see "Understanding VBScript: The Windows Shell Object Model," October 2000.)

After you create an instance of the Folder object, you can use its properties and methods. The Folder Object exposes three properties:

  • Application—returns a reference to the folder's Application object
  • ParentFolder—returns a reference to the folder's parent Folder object
  • Title—returns the folder's display name (i.e., the name that appears in Windows Explorer)

Table 1 shows the Folder object's methods. As you can see, the functions that you can perform with these methods are quite similar to the functions you can perform manually in the Windows shell. The method that you'll probably use the most is Items. Before I discuss the Items method, though, let me first show you how to use the Folder object's CopyHere, MoveHere, GetDetailsOf, and ParseName methods and discuss the limitations of the NewFolder method and Count property.

Copying and Moving Folders
The CopyHere method has the syntax

CopyHere elements, [options]

The mandatory first argument, elements, specifies the item or items to copy in the current folder. You can specify filenames, FolderItem objects, or FolderItems objects. The optional second argument, options, specifies how you want to perform the copy operation. Because CopyHere uses the same internal function as Windows Explorer to accomplish a copy operation, you might encounter Windows Explorer's animation if you copy several files or lengthy files. You can use flags to somewhat control how you want the copy operation to take place. Table 2 includes the most frequently used flags. For the complete list, check out the Microsoft Developer Network (MSDN) Online Library at http://msdn.microsoft.com/library/psdk/ shellcc/shell/structures/shfileopstruct.htm#shfileopstruct.

As Table 2 shows, each flag has a value. To use the flags, you assign the options argument the value of the flag or flags you want. For example, if you're running Windows 2000, you can efficiently duplicate files when you use CopyHere with the value of 8192 (i.e., &H2000) to copy an HTML page. When you use Microsoft Internet Explorer (IE) to save an HTML page, you obtain an .htm file and a subdirectory. The subdirectory contains all the accessory files (e.g., image files, scripts) for that page. If you use CopyHere with an option of 8192 under Win2K to copy an HTML page, CopyHere automatically copies the HTML page and all the accessory files in the subdirectory.

The MoveHere method's syntax is

MoveHere elements, [options]

MoveHere works the same way as CopyHere, except that MoveHere moves instead of copies the files into the current folder.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.