2. System Information
Get Drive information in current system
Get info of specific Drive
Available Free Space
DriveFormat
IsReady
Name
RootDirectory
TotalFreeSpace
TotalSize
VolumeLabel
List Drive
List Sub folders
List Files
3. System.IO.FileInfo
Provides properties and instance methods for the creation, copying,
deletion, moving, and opening of files, and aids in the creation
of FileStream objects. This class cannot be inherited.
System.IO.DirectoryInfo
Exposes instance methods for creating, moving, and enumerating
through directories and subdirectories. This class cannot be
inherited.
System.IO.DriveInfo
Provides access to information on a drive.
System.IO.Directory
Exposes static methods for creating, moving, and enumerating
through directories and subdirectories. This class cannot be
inherited.
4. Public Attributes
Gets or sets the attributes for the current file or directory.
(Inherited from FileSystemInfo.)
Public CreationTime
Gets or sets the creation time of the current file or directory.
(Inherited from FileSystemInfo.)
Public property CreationTimeUtc
Gets or sets the creation time, in coordinated universal time
(UTC), of the current file or directory. (Inherited from
FileSystemInfo.)
5. Public Directory
Gets an instance of the parent directory.
Public DirectoryName
Gets a string representing the directory's full path.
Public Exists
Gets a value indicating whether a file exists. (Overrides
FileSystemInfo.Exists.)
6. Public Extension
Gets the string representing the extension part of the file.
(Inherited from FileSystemInfo.)
Public FullName
Gets the full path of the directory or file. (Inherited from
FileSystemInfo.)
Public property IsReadOnly
Gets or sets a value that determines if the current file is read
only.
7. Public LastAccessTime
Gets or sets the time the current file or directory was last
accessed. (Inherited from FileSystemInfo.)
Public property LastAccessTimeUtc
Gets or sets the time, in coordinated universal time (UTC),
that the current file or directory was last accessed. (Inherited
from FileSystemInfo.)
Public LastWriteTime
Gets or sets the time when the current file or directory was last
written to. (Inherited from FileSystemInfo.)
8. Public property LastWriteTimeUtc
Gets or sets the time, in coordinated universal time (UTC),
when the current file or directory was last written to.
(Inherited from FileSystemInfo.)
Public Length
Gets the size, in bytes, of the current file.
Public Name
Gets the name of the file. (Overrides FileSystemInfo.Name.)
9. DirectoryInfo Class
Exposes instance methods for creating, moving, and
enumerating through directories and subdirectories.
This class cannot be inherited.
Properties
10. Public property Attributes
Gets or sets the attributes for the current file or directory.
(Inherited from FileSystemInfo.)
Public property CreationTime
Gets or sets the creation time of the current file or directory.
(Inherited from FileSystemInfo.)
Public property CreationTimeUtc
Gets or sets the creation time, in coordinated universal time
(UTC), of the current file or directory. (Inherited from
FileSystemInfo.)
11. Public Exists
Gets a value indicating whether the directory exists.
(Overrides FileSystemInfo.Exists.)
Public Extension
Gets the string representing the extension part of the file.
(Inherited from FileSystemInfo.)
Public FullName
Gets the full path of the directory or file. (Inherited from
FileSystemInfo.)
12. Public LastAccessTime
Gets or sets the time the current file or directory was last
accessed. (Inherited from FileSystemInfo.)
Public LastAccessTimeUtc
Gets or sets the time, in coordinated universal time (UTC),
that the current file or directory was last accessed. (Inherited
from FileSystemInfo.)
Public LastWriteTime
Gets or sets the time when the current file or directory was
last written to. (Inherited from FileSystemInfo.)
13. Public property LastWriteTimeUtc
Gets or sets the time, in coordinated universal time (UTC),
when the current file or directory was last written to.
(Inherited from FileSystemInfo.)
Public Name
Gets the name of this DirectoryInfo instance. (Overrides
FileSystemInfo.Name.)
Public Parent
Gets the parent directory of a specified subdirectory.
Public Root
Gets the root portion of the directory.
14. System.IO.DriveInfo
Public property AvailableFreeSpace
Indicates the amount of available free space on a drive, in
bytes.
Public property DriveFormat
Gets the name of the file system, such as NTFS or FAT32.
Public property DriveType
Gets the drive type, such as CD-ROM, removable, network,
or fixed.
15. Public property IsReady
Gets a value that indicates whether a drive is ready.
Public property Name
Gets the name of a drive, such as C:.
Public property RootDirectory
Gets the root directory of a drive.
16. Public property TotalFreeSpace
Gets the total amount of free space available on a drive, in
bytes.
Public property TotalSize
Gets the total size of storage space on a drive, in bytes.
Public property VolumeLabel
Gets or sets the volume label of a drive.
17. Methods DriveInfo and Example
GetDrives()
Retrieves the drive names of all logical drives on a
computer.
18. Directory Class
Methods
Delete(String)
Deletes an empty directory from a specified path.
Exists()
Determines whether the given path refers to an existing directory
on disk.
GetAccessControl(String)
Gets a DirectorySecurity object that encapsulates the access
control list (ACL) entries for a specified directory
GetCurrentDirectory()
Returns the names of subdirectories (including their paths) in the
specified directory.
19. Example of Drive Info
public static void Main()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 15} bytes",
d.AvailableFreeSpace);
Console.WriteLine(
" Total available space: {0, 15} bytes",
d.TotalFreeSpace);
Console.WriteLine(
" Total size of drive: {0, 15} bytes ",
d.TotalSize);
}
}
System.Console.ReadLine();
}
20. Drive C:
File type: Fixed
Volume label: Windows
File system: NTFS
Available space to current user: 135662944256 bytes
Total available space: 135662944256 bytes
Total size of drive: 320070479872 bytes
Drive D:
File type: CDRom
Drive Q:
File type: Fixed
21. Example of File info
Total PhysicalMemory example