CHAPTER 20 FILE I/O AND OBJECT SERIALIZATION
Attributes: Directory
Root: C:\
**************************
Enumerating Files with the DirectoryInfo Type
In addition to obtaining basic details of an existing directory, you can extend the current example to use
some methods of the DirectoryInfo type. First, you can leverage the GetFiles() method to obtain
information about all *.jpg files located under the C:\Windows\Web\Wallpaper directory.
Note If your machine does not have a C:\Windows\Web\Wallpaper directory, retrofit this code to read files of a
directory on your machine (e.g., to read all *.bmp files from the C:\Windows directory).
The GetFiles() method returns an array of FileInfo objects, each of which exposes details of a
particular file (you will learn the full details of the FileInfo type later in this chapter). Assume that you
have the following static method of the Program class, which you call from Main():
static void DisplayImageFiles()
{
DirectoryInfo dir = new DirectoryInfo(@"C:\Windows\Web\Wallpaper");
// Get all files with a *.jpg extension.
FileInfo[] imageFiles = di