Rediger

Del via


Win32_Directory class

The Win32_Directory WMI class represents a directory entry on a computer system running Windows. A directory is a type of file that logically groups data files and provides path information for the grouped files. Example: C:\TEMP. Win32_Directory does not include directories of network drives.

The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties are listed in alphabetic order, not MOF order.

Syntax

[Dynamic, Provider("CIMWin32"), UUID("{8502C4C7-5FBB-11D2-AAC1-006008C78BC7}"), AMENDMENT]
class Win32_Directory : CIM_Directory
{
  string   Caption;
  string   Description;
  datetime InstallDate;
  string   Name;
  string   Status;
  uint32   AccessMask;
  boolean  Archive;
  boolean  Compressed;
  string   CompressionMethod;
  string   CreationClassName;
  datetime CreationDate;
  string   CSCreationClassName;
  string   CSName;
  string   Drive;
  string   EightDotThreeFileName;
  boolean  Encrypted;
  string   EncryptionMethod;
  string   Extension;
  string   FileName;
  uint64   FileSize;
  string   FileType;
  string   FSCreationClassName;
  string   FSName;
  boolean  Hidden;
  uint64   InUseCount;
  datetime LastAccessed;
  datetime LastModified;
  string   Path;
  boolean  Readable;
  boolean  System;
  boolean  Writeable;
};

Members

The Win32_Directory class has these types of members:

Methods

The Win32_Directory class has these methods.

Method Description
ChangeSecurityPermissions Class method that changes the security permissions for the logical file specified in the object path.
ChangeSecurityPermissionsEx Class method that changes the security permissions for the logical file specified in the object path.
Compress Class method that compresses the logical file (or directory) specified in the object path.
CompressEx Class method that compresses the logical file (or directory) specified in the object path.
Copy Class method that copies the logical file or directory specified in the object path to the location specified by the input parameter.
CopyEx Class method that copies the logical file or directory specified in the object path to the location specified by the FileName parameter.
Delete Class method that deletes the logical file (or directory) specified in the object path.
DeleteEx Class method that deletes the logical file (or directory) specified in the object path.
GetEffectivePermission Class method that determines whether the caller has the aggregated permissions specified by the Permissions argument not only on the file object, but on the share the file or directory resides on (if it is on a share).
Rename Class method that renames the logical file (or directory) specified in the object path.
TakeOwnerShip Class method that obtains ownership of the logical file specified in the object path.
TakeOwnerShipEx Class method that obtains ownership of the logical file specified in the object path.
Uncompress Class method that uncompresses the logical file (or directory) specified in the object path.
UncompressEx Class method that uncompresses the logical file (or directory) specified in the object path.

Properties

The Win32_Directory class has these properties.

AccessMask

Data type: uint32

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("Access Rights")

Bitmask that represents the access rights required to access or perform specific operations on the directory. For bit values, see File and Directory Access Rights Constants.

Note

On FAT volumes, the FULL_ACCESS value is returned instead, which indicates no security has been set on the object.

This property is inherited from CIM_LogicalFile.

FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory) (1)

Grants the right to read data from the file. For a directory, this value grants the right to list the contents of the directory.

FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory) (2)

Grants the right to write data to the file. For a directory, this value grants the right to create a file in the directory.

FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY (4)

Grants the right to append data to the file. For a directory, this value grants the right to create a subdirectory.

FILE_READ_EA (8)

Grants the right to read extended attributes.

FILE_WRITE_EA (16)

Grants the right to write extended attributes.

FILE_EXECUTE (file) or FILE_TRAVERSE (directory) (32)

Grants the right to execute a file. For a directory, the directory can be traversed.

FILE_DELETE_CHILD (directory) (64)

Grants the right to delete a directory and all of the files it contains (its children), even if the files are read-only.

FILE_READ_ATTRIBUTES (128)

Grants the right to read file attributes.

FILE_WRITE_ATTRIBUTES (256)

Grants the right to change file attributes.

DELETE (65536)

Grants delete access.

READ_CONTROL (131072)

Grants read access to the security descriptor and owner.

WRITE_DAC (262144)

Grants write access to the discretionary ACL.

WRITE_OWNER (524288)

Assigns the write owner.

SYNCHRONIZE (1048576)

Synchronizes access and allows a process to wait for an object to enter the signaled state.

ACCESS_SYSTEM_SECURITY (18809343)

Controls the ability to get or set the SACL in an object's security descriptor.

Archive

Data type: boolean

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("Should Be Archived")

Indicates 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. If True, the file should be archived.

This property is inherited from CIM_LogicalFile.

Caption

Data type: string

Access type: Read-only

Qualifiers: MaxLen (64), DisplayName ("Caption")

A short textual description of the object.

This property is inherited from CIM_ManagedSystemElement.

Compressed

Data type: boolean

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("Compressed")

Indicates 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. If True, the file is compressed.

This property is inherited from CIM_LogicalFile.

CompressionMethod

Data type: string

Access type: Read-only

Qualifiers: DisplayName ("Compression Method")

Algorithm or tool (usually a method) used to compress the logical file. If it is not possible (or not desired) to describe the compression scheme (perhaps because it is not known), use the following words: "Unknown" to represent that it is not known whether the logical file is compressed; "Compressed" to represent that the file is compressed, but either its compression scheme is not known or not disclosed; and "Not Compressed" to represent that the logical file is not compressed.

This property is inherited from CIM_LogicalFile.

CreationClassName

Data type: string

Access type: Read-only

Qualifiers: CIM_Key, DisplayName ("Class Name")

Name of the first concrete class to appear in the inheritance chain used in the creation of an instance. When used with the other key properties of the class, this property allows all instances of this class and its subclasses to be uniquely identified.

This property is inherited from CIM_LogicalFile.

CreationDate

Data type: datetime

Access type: Read-only

Qualifiers: DisplayName ("Creation Date")

Date that the file system object was created. For more information on working with WMI date and time formats, see WMI Tasks: Dates and Times.

This property is inherited from CIM_LogicalFile.

CSCreationClassName

Data type: string

Access type: Read-only

Qualifiers: Propagated ("CIM_FileSystem.CSCreationClassName"), CIM_Key, DisplayName ("Computer System Class Name")

Creation class name of the scoping computer system.

This property is inherited from CIM_LogicalFile.

CSName

Data type: string

Access type: Read-only

Qualifiers: Propagated ("CIM_FileSystem.CSName"), CIM_Key, DisplayName ("Computer System Name")

Name of the computer where the file system object is stored.

This property is inherited from CIM_LogicalFile.

Description

Data type: string

Access type: Read-only

Qualifiers: DisplayName ("Description")

A textual description of the object.

This property is inherited from CIM_ManagedSystemElement.

Drive

Data type: string

Access type: Read-only

Qualifiers: Fixed, Schema ("Win32"), DisplayName ("Drive")

Drive letter of the drive (including colon) where the file system object is stored.

Example: "c:"

This property is inherited from CIM_LogicalFile.

EightDotThreeFileName

Data type: string

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("Eight Dot Three File Name")

MS-DOS -compatible name for the folder.

Example: "c:\progra~1"

This property is inherited from CIM_LogicalFile.

Encrypted

Data type: boolean

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("Encrypted")

Indicates whether or not the folder has been encrypted. If True, the folder is encrypted.

This property is inherited from CIM_LogicalFile.

EncryptionMethod

Data type: string

Access type: Read-only

Qualifiers: DisplayName ("Encryption Method")

Algorithm or tool used to encrypt the logical file. If it is not possible (or not desired) to describe the encryption scheme (perhaps for security reasons), use the following words: "Unknown" to represent that it is not known whether the logical file is encrypted; "Encrypted" to represent that the file is encrypted, but either its encryption scheme is not known or not disclosed; and "Not Encrypted" to represent that the logical file is not encrypted.

This property is inherited from CIM_LogicalFile.

Extension

Data type: string

Access type: Read-only

Qualifiers: Fixed, Schema ("Win32"), DisplayName ("File Extension")

File name extension for the file system object, not including the dot (.) that separates the extension from the file name.

Examples: "txt", "mof", "mdb"

This property is inherited from CIM_LogicalFile.

FileName

Data type: string

Access type: Read-only

Qualifiers: Fixed, Schema ("Win32"), DisplayName ("File Name")

File name (without the dot or extension) of the file.

Example: "autoexec"

This property is inherited from CIM_LogicalFile.

FileSize

Data type: uint64

Access type: Read-only

Qualifiers: DisplayName ("Size"), Units ("bytes")

Size 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.

For more information about using uint64 values in scripts, see Scripting in WMI.

This property is inherited from CIM_LogicalFile.

FileType

Data type: string

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("File Type")

File type (indicated by the Extension property).

For example, an .mdb file is likely to have the file type Microsoft Access Application. An .asp file likely has the file type HTML Document. Folders are typically reported simply as Folder.

This property is inherited from CIM_LogicalFile.

FSCreationClassName

Data type: string

Access type: Read-only

Qualifiers: Propagated ("CIM_FileSystem.CreationClassName"), CIM_Key, DisplayName ("File System Class Name")

Class of the file system.

This property is inherited from CIM_LogicalFile.

FSName

Data type: string

Access type: Read-only

Qualifiers: Propagated ("CIM_FileSystem.Name"), CIM_Key, DisplayName ("File System Name")

Type of file system (NTFS, FAT, FAT32) installed on the drive where the file or folder is located.

This property is inherited from CIM_LogicalFile.

Hidden

Data type: boolean

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("Hidden")

Indicates whether the file system object is hidden. If True, the file is hidden.

This property is inherited from CIM_LogicalFile.

InstallDate

Data type: datetime

Access type: Read-only

Qualifiers: MappingStrings ("MIF.DMTF|ComponentID|001.5"), DisplayName ("Install Date")

Indicates when the object was installed. Lack of a value does not indicate that the object is not installed.

This property is inherited from CIM_ManagedSystemElement.

InUseCount

Data type: uint64

Access type: Read-only

Qualifiers: DisplayName ("Current File Open Count")

Number of "file opens" that are currently active against the file.

This property is inherited from CIM_LogicalFile.

For more information about using uint64 values in scripts, see Scripting in WMI.

LastAccessed

Data type: datetime

Access type: Read-only

Qualifiers: DisplayName ("Last Accessed")

Date the file was last accessed. For more information on working with WMI date and time formats, see WMI Tasks: Dates and Times.

This property is inherited from CIM_LogicalFile.

LastModified

Data type: datetime

Access type: Read-only

Qualifiers: DisplayName ("Last Modified")

Date the file was last modified. For more information on working with WMI date and time formats, see WMI Tasks: Dates and Times.

This property is inherited from CIM_LogicalFile.

Name

Data type: string

Access type: Read-only

Qualifiers: Key

The Name property is a string representing the inherited name that serves as a key of a logical file instance within a file system. Full path names should be provided. Example: C:\Windows\system\win.ini

This property is inherited from CIM_LogicalFile.

Path

Data type: string

Access type: Read-only

Qualifiers: Fixed, Schema ("Win32"), DisplayName ("Path")

Path for the file. 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 \.

This property is inherited from CIM_LogicalFile.

Readable

Data type: boolean

Access type: Read-only

Qualifiers: DisplayName ("Readable")

Indicates whether you can read items in the folder. If True, the file can be read.

This property is inherited from CIM_LogicalFile.

Status

Data type: string

Access type: Read-only

Qualifiers: MaxLen (10), DisplayName ("Status")

String that indicates the current status of the object.

This property is inherited from CIM_ManagedSystemElement.

Values include the following:

OK ("OK")

Error ("Error")

Degraded ("Degraded")

Unknown ("Unknown")

Pred Fail ("Pred Fail")

Starting ("Starting")

Stopping ("Stopping")

Service ("Service")

Stressed ("Stressed")

NonRecover ("NonRecover")

No Contact ("No Contact")

Lost Comm ("Lost Comm")

System

Data type: boolean

Access type: Read-only

Qualifiers: Schema ("Win32"), DisplayName ("System File")

Indicates whether the object is a system file. If True, the file is a system file

This property is inherited from CIM_LogicalFile.

Writeable

Data type: boolean

Access type: Read-only

Qualifiers: DisplayName ("Writeable")

If True, the file can be written.

This property is inherited from CIM_LogicalFile.

Remarks

The Win32_Directory class is derived from CIM_Directory.

Overview

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.

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:\.

You can retrieve the properties of any folder in the file system using the Win32_Directory class. The properties available using this class are shown in Table 11.1. To retrieve the properties for a single folder, construct a Windows Query Language (WQL) query for the Win32_Directory class, making sure that you include the name of the folder. For example, this query binds to the folder D:\Archive:

Copy "SELECT * FROM Win32_Directory WHERE Name = 'D:\\Archive'"

When specifying a file or folder name in a WQL query, be sure you use two backslashes (\\) to separate path components.

If you want to limit data retrieval to a single disk drive, include a Where clause specifying the drive letter. For example, this query returns a list of all the folders on drive C:

"SELECT * FROM Win32_Directory WHERE Drive = 'C:'"

If you need to enumerate all the folders on a computer, be aware that this query can take an extended time to complete.

Examples

The following VBScript sample retrieves properties for the folder C:\Scripts.

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE Name = 'c:\\Scripts'")
For Each objFolder in colFolders
 Wscript.Echo "Archive: " & objFolder.Archive
 Wscript.Echo "Caption: " & objFolder.Caption
 Wscript.Echo "Compressed: " & objFolder.Compressed
 Wscript.Echo "Compression method: " & objFolder.CompressionMethod
 Wscript.Echo "Creation date: " & objFolder.CreationDate
 Wscript.Echo "Encrypted: " & objFolder.Encrypted
 Wscript.Echo "Encryption method: " & objFolder.EncryptionMethod
 Wscript.Echo "Hidden: " & objFolder.Hidden
 Wscript.Echo "In use count: " & objFolder.InUseCount
 Wscript.Echo "Last accessed: " & objFolder.LastAccessed
 Wscript.Echo "Last modified: " & objFolder.LastModified
 Wscript.Echo "Name: " & objFolder.Name
 Wscript.Echo "Path: " & objFolder.Path
 Wscript.Echo "Readable: " & objFolder.Readable
 Wscript.Echo "System: " & objFolder.System
 Wscript.Echo "Writeable: " & objFolder.Writeable
Next

The following VBScript sample returns a list of all the hidden folders on a computer.

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE Hidden = True")
For Each objFile in colFiles
 Wscript.Echo objFile.Name
Next

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

See also

CIM_Directory

Operating System Classes