复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace aboutio
{
class Program
{
static void Main(string[] args)
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
if(drive.IsReady)
Console.WriteLine("类型:{0} 卷标:{1} 名称:{2} 总空间:{3} 剩余空间:{4}",drive.DriveType, drive.VolumeLabel,drive.Name,drive.TotalSize,drive.TotalFreeSpace);
else
Console.WriteLine("类型:{0} is not ready",drive.DriveType);
}
Console.ReadLine();
}
}
}
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
namespace UseFileSystemWatcher
{
class Program
{
static void Main(string[] args)
{
//声明要监视的目录
string watchPath = "D://watch";
FileSystemWatcher watcher = new FileSystemWatcher(watchPath, "*.*");
//添加文件变化处理事件
watcher.Changed += new FileSystemEventHandler(Watcher_Changed);
//添加文件创建处理事件
watcher.Created += new FileSystemEventHandler(Watcher_Created);
//添加文件删除处理事件
watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted);
//添加错误处理
watcher.Error += new ErrorEventHandler(Watcher_Error);
//启动监视
watcher.EnableRaisingEvents = true;
Thread.Sleep(1000 * 60);
Console.WriteLine("press any key to exit..");
Console.Read();
}
static void Watcher_Error(object sender, ErrorEventArgs e)
{
Console.WriteLine("错误:" + e.ToString());
}
static void Watcher_Deleted(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.ChangeType + ":" + e.FullPath);
}
static void Watcher_Created(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.ChangeType + ":" + e.FullPath);
}
static void Watcher_Changed(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.ChangeType + ":" + e.FullPath);
}
}
}
新闻热点
疑难解答
图片精选