Csharp/C Sharp by API/System.IO/DriveInfo
Содержание
DriveInfo.AvailableFreeSpace
using System;
using System.IO;
class MainClass {
static void Main(string[] args) {
FileInfo file = new FileInfo("c:\\a.txt");
// Display drive information.
DriveInfo drv = new DriveInfo(file.FullName);
Console.Write("Drive: ");
Console.WriteLine(drv.Name);
if (drv.IsReady) {
Console.Write("Drive free space: ");
Console.WriteLine(drv.AvailableFreeSpace.ToString());
}
}
}
DriveInfo.DriveFormat
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class Program {
static void Main(string[] args) {
// Get info regarding all drives.
DriveInfo[] myDrives = DriveInfo.GetDrives();
// Now print stats.
foreach (DriveInfo d in myDrives) {
Console.WriteLine("Name: {0}", d.Name);
Console.WriteLine("Type: {0}", d.DriveType);
if (d.IsReady) {
Console.WriteLine("Free space: {0}", d.TotalFreeSpace);
Console.WriteLine("Format: {0}", d.DriveFormat);
Console.WriteLine("Label: {0}\n", d.VolumeLabel);
}
}
Console.ReadLine();
}
}
DriveInfo.DriveType
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class Program {
static void Main(string[] args) {
// Get info regarding all drives.
DriveInfo[] myDrives = DriveInfo.GetDrives();
// Now print stats.
foreach (DriveInfo d in myDrives) {
Console.WriteLine("Name: {0}", d.Name);
Console.WriteLine("Type: {0}", d.DriveType);
if (d.IsReady) {
Console.WriteLine("Free space: {0}", d.TotalFreeSpace);
Console.WriteLine("Format: {0}", d.DriveFormat);
Console.WriteLine("Label: {0}\n", d.VolumeLabel);
}
}
Console.ReadLine();
}
}
DriveInfo.Name
using System;
using System.IO;
class MainClass {
static void Main(string[] args) {
FileInfo file = new FileInfo("c:\\a.txt");
// Display drive information.
DriveInfo drv = new DriveInfo(file.FullName);
Console.Write("Drive: ");
Console.WriteLine(drv.Name);
}
}
DriveInfo.RootDirectory
using System;
using System.IO;
class MainClass {
static void Main(string[] args) {
if (args.Length == 1) {
DriveInfo drive = new DriveInfo(args[0]);
Console.Write("Free space in {0}-drive (in kilobytes): ", args[0]);
Console.WriteLine(drive.AvailableFreeSpace / 1024);
return;
}
foreach (DriveInfo drive in DriveInfo.GetDrives()) {
Console.WriteLine("{0} - {1} KB",drive.RootDirectory,
drive.AvailableFreeSpace / 1024
);
}
}
}
DriveInfo.TotalFreeSpace
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class Program {
static void Main(string[] args) {
// Get info regarding all drives.
DriveInfo[] myDrives = DriveInfo.GetDrives();
// Now print stats.
foreach (DriveInfo d in myDrives) {
Console.WriteLine("Name: {0}", d.Name);
Console.WriteLine("Type: {0}", d.DriveType);
if (d.IsReady) {
Console.WriteLine("Free space: {0}", d.TotalFreeSpace);
Console.WriteLine("Format: {0}", d.DriveFormat);
Console.WriteLine("Label: {0}\n", d.VolumeLabel);
}
}
Console.ReadLine();
}
}
DriveInfo.VolumeLabel
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class Program {
static void Main(string[] args) {
// Get info regarding all drives.
DriveInfo[] myDrives = DriveInfo.GetDrives();
// Now print stats.
foreach (DriveInfo d in myDrives) {
Console.WriteLine("Name: {0}", d.Name);
Console.WriteLine("Type: {0}", d.DriveType);
if (d.IsReady) {
Console.WriteLine("Free space: {0}", d.TotalFreeSpace);
Console.WriteLine("Format: {0}", d.DriveFormat);
Console.WriteLine("Label: {0}\n", d.VolumeLabel);
}
}
Console.ReadLine();
}
}
new DriveInfo(String fileName)
using System;
using System.IO;
class MainClass {
static void Main(string[] args) {
FileInfo file = new FileInfo("c:\\a.txt");
// Display drive information.
DriveInfo drv = new DriveInfo(file.FullName);
Console.Write("Drive: ");
Console.WriteLine(drv.Name);
}
}