在 .NET Framework 中,可以使用以下类来访问文件系统信息:
-
System.IO..::.FileInfo
-
System.IO..::.DirectoryInfo
-
System.IO..::.DriveInfo
-
System.IO..::.Directory
-
System.IO..::.File
FileInfo 和 DirectoryInfo 类表示文件或目录,包含公开 NTFS 文件系统所支持的很多文件属性 (Attribute) 的属性 (Property),同时还包含用于打开、关闭、移动和删除文件和文件夹的方法。可以通过将表示文件、文件夹或驱动器名称的字符串传递到下面的构造函数来创建这些类的实例:
using System;
using System.Collections.Generic;
namespace myns
{
class FileSysInfo
{
static void Main()
{
// You can also use System.Environment.GetLogicalDrives to
// obtain names of all logical drives on the computer.
System.IO.DriveInfo di = new System.IO.DriveInfo(@"C:\");
Console.WriteLine(di.To