352
LESSON 30 Using File system Classes
The DirectoryInfo class also provides a few useful properties, which are summarized in Table 30-3.
TABLE 303
PROPERTY PURPOSE
Attributes
The directory’s attributes, such as Compressed, Hidden, or System.
CreationTime
The time at which the directory was created.
Exists
Returns True if the directory actually exists.
FullName
Gives the directory’s fully qualified path.
LastAccessTime
The time at which the directory was last accessed.
LastWriteTime
The time at which the directory was last written.
Name
The directory’s name without the path.
Parent
A DirectoryInfo representing this directory’s parent directory.
Root
The directory’s file system root.
Example program UseDirectoryInfo (found in this lesson’s code download) uses a DirectoryInfo
object to display information about directories.
THE DIRECTORY CLASS
The Directory class provides static methods for manipulating directories (see Table 30-4). For
simple tasks these are sometimes easier to use than the comparable
DirectoryInfo class methods
because you don’t need to create a
DirectoryInfo object to use them.
TABLE 304
METHOD PURPOSE
CreateDirectory
Creates the directory and any missing directories in its path up to the root.
Delete
Deletes a directory.
Exists
Returns true if the directory exists.
GetCreationTime
Returns the time at which the file was created.
GetDirectories
Returns a directory’s subdirectories.
GetDirectoryRoot
Returns the directory’s root.
GetFiles
Returns a directory’s files, optionally looking for files matching a pattern.
GetLastAccessTime
Returns the time at which a directory was last accessed.
596906c30.indd 352 4/7/10 12:34:25 PM