Folders and Folder Objects

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Folders are file system objects designed to contain other file system objects. This does not mean that all folders are alike, however. Instead, folders can vary considerably. Some folders are operating system folders, which generally should not be modified by a script. Some folders are read-only, which means that users can access the contents of that folder but cannot add to, delete from, or modify those contents. Some folders are compressed for optimal storage, while others are hidden and not visible to users.

WMI uses the Win32_Directory class to manage folders. Significantly, the properties and methods available in this class are identical to the properties and methods available in the CIM_DataFile class, the class used to manage files. This means that after you have learned how to manage folders using WMI, you will, without any extra work, also know how to manage files.

Some of the more useful Win32_Directory class properties are shown in Table 11.1. These properties are identical to the properties found in the CIM_DataFile class.

Table 11.1   Win32_Directory Properties

PropertyDescription
ArchiveBoolean value indicating whether the archive bit on the folder has been set. The archive bit is used by backup programs to identify files that should be backed up.
CompressedBoolean value indicating whether or not the folder has been compressed. WMI recognizes folders compressed using WMI itself or using the graphical user interface; it does not, however, recognize .ZIP files as being compressed.
CompressionMethodMethod used to compress the file system object. Often reported simply as "Compressed."
CreationDateDate that the file system object was created.
CSNameName of the computer where the file system object is stored.
DriveDrive letter of the drive where the file system object is stored.
EightDotThreeFileNameMS-DOS® compatible name for the folder. For example, the EightDotThreeFileName for the folder C:\Program Files might be C:\Progra~1.
EncryptedBoolean value indicating whether or not the folder has been encrypted.
EncryptionMethodMethod used to encrypt the file system object. Often reported simply as "Encryption."
ExtensionFile name extension for the file system object, not including the dot (.) that separates the extension from the file name.
FileNameName of the file system object, not including the extension.
FileSizeSize of the file system object, in bytes. Although folders possess a FileSize property, the value 0 is always returned. To determine the size of a folder, use the FileSystemObject or add up the size of all the files stored in the folder.
FileTypeType of file system object, based on the extension and the default registration for that extension. For example, an .mdb file is likely to have the file type Microsoft Access Application. An .htm file likely has the file type HTML Document. Folders are typically reported simply as Folder.
FSNameType of file system (NTFS, FAT, FAT32) installed on the drive where the file or folder is located.
HiddenBoolean value indicating whether the file system object is hidden.
LastAccessedDate that the object was last accessed.
LastModifiedDate that the object was last modified.
NameFull path name of the file system object. For example: c:\windows\system32\wbem.
PathPath for the folder. The path includes the leading and trailing backslashes, but not the drive letter or the folder name. For the folder c:\windows\system32\wbem, the path is \windows\system32\. For the folder c:\scripts, the path is \.
Readable Boolean value indicating whether you can read items in the folder.
SystemBoolean value indicating whether the object is a system folder.
WriteableBoolean value indicating whether you can write to the folder.

The relationship between the Win32_Directory properties and the folder properties available through Windows Explorer is shown in Figure 11.2.

Figure 11.2   Win32_Directory and Windows Explorer

Win32_Directory and Windows Explorer

In addition, the Win32_Directory and CIM_DataFile classes share the same set of methods. Some of the more commonly used methods are shown in Table 11.2.

Table 11.2   Win32_Directory and CIM_DataFile Methods

MethodDescription
CopyCopies the file system object to a new location.
RenameRenames the file system object.
DeleteDeletes the object from the file system.
CompressCompresses a file system object using Windows compression.
UncompressUncompresses a file system object that was compressed using Windows compression.

These methods return the values shown in Table 11.3. Because files and folders share the same set of methods, you can copy, delete, or rename both files and folders using the same approach. Similarly, you can easily add error handling to file and folder scripts; the code used to interpret error codes in one script is exactly the same as the code used to interpret error codes in any other file or folder management script.

Table 11.3   WMI File and Folder Return Values

ValueDescription
0Operation completed successfully.
2Access denied.
8An unspecified failure occurred.
9Invalid name.
10Object already exists.
11The file system is not NTFS.
12The platform is not Windows NT®, Windows 2000, or Windows® XP.
13The drive is not the same.
14The folder is not empty.
15A sharing violation has occurred.
16Invalid file.
17The user does not have the rights required to perform this operation.
21Invalid parameter.

In addition to the Win32_Directory class, the Win32_Subdirectory association class is also used to manage files and folders. The Win32_Subdirectory class relates a folder and its immediate subfolders. For example, in the folder structure C:\Scripts\Logs, Logs is a subfolder of Scripts, and Scripts is a subfolder of the root folder C:\. However, Logs is not considered a subfolder of C:\.


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