
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
746
|
Chapter 12: Filesystem I/O
This code will display something like the following, though of course each system is
different and the results will vary:
Drive C:\ is ready.
AvailableFreeSpace: 143210795008
DriveFormat: NTFS
DriveType: Fixed
Name: C:\
RootDirectory.FullName: C:\
TotalFreeSpace: 143210795008
TotalSize: 159989886976
VolumeLabel: Vol1
Drive D:\ is ready.
AvailableFreeSpace: 0
DriveFormat: UDF
DriveType: CDRom
Name: D:\
RootDirectory.FullName: D:\
TotalFreeSpace: 0
TotalSize: 3305965568
VolumeLabel: Vol2
Drive E:\ is ready.
AvailableFreeSpace: 4649025536
DriveFormat: UDF
DriveType: CDRom
Name: E:\
RootDirectory.FullName: E:\
TotalFreeSpace: 4649025536
TotalSize: 4691197952
VolumeLabel: Vol3
Drive F:\ is not ready.
Of particular interest are the IsReady and AvailableFreeSpace properties. The IsReady
property determines if the drive is ready to be queried, written to, or read from. The
AvailableFreeSpace property returns the free space on that drive in bytes.
Discussion
The DriveInfo class has been added to the .NET Framework to allow you to easily
query information on one particular drive or on all drives in the system. To query the
information from a single drive you would use the code in Example 12-15.
Example 12-15. Getting information from a specific drive
DriveInfo drive = new DriveInfo("D"); ...