DirectoryInfo对比Directory
Directory 与 DirectoryInfo 区别
前者继承System.Object,后者继承抽象类FileSystemInfo
前者是静态类,后者是非静态类,需要new创建实例
前者返回的类型是简单字符串,后者返回的是强类型如FileInfo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DirectoryInfo对象
{
class Program
{
static void Main(string[] args)
{
ShowWindowsDirectoryInfo();
}
static void ShowWindowsDirectoryInfo()
{
DirectoryInfo dir = new DirectoryInfo(@"G:\c#");
//获取所有文件
FileInfo [] files = dir.GetFiles("*.png",SearchOption.AllDirectories);
Console.WriteLine("************以下是文件信息**************");
foreach (FileInfo f in files)
{
Console.WriteLine("FileName:{0}",f.Name);
Console.WriteLine("FullName:{0}",f.FullName);
}
Console.WriteLine("****************以下是目录信息*****************");
Console.WriteLine("FullName:{0}",dir.FullName);
Console.WriteLine("Name:{0}",dir.Name);
Console.WriteLine("Creation:{0}",dir.CreationTime);
Console.WriteLine("Attributes:{0}",dir.Attributes);
Console.WriteLine("Root:{0}",dir.Root);
}
}
}
posted on 2011-05-25 19:05 BarneyZhang 阅读(1322) 评论(0) 编辑 收藏 举报