復制代碼 代碼如下:
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);
}
}
}
新聞熱點
疑難解答
圖片精選