本文整理汇总了C#中System.IO.DriveInfo类的典型用法代码示例。如果您正苦于以下问题:C# DriveInfo类的具体用法?C# DriveInfo怎么用?C# DriveInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DriveInfo类属于System.IO命名空间,在下文中一共展示了DriveInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AbstractHarddrive
protected AbstractHarddrive(ISmart smart, string name,
string firmwareRevision, int index,
IEnumerable<SmartAttribute> smartAttributes, ISettings settings)
: base(name, new Identifier("hdd",
index.ToString(CultureInfo.InvariantCulture)), settings)
{
this.firmwareRevision = firmwareRevision;
this.smart = smart;
handle = smart.OpenDrive(index);
if (handle != smart.InvalidHandle)
smart.EnableSmart(handle, index);
this.index = index;
this.count = 0;
this.smartAttributes = new List<SmartAttribute>(smartAttributes);
string[] logicalDrives = smart.GetLogicalDrives(index);
List<DriveInfo> driveInfoList = new List<DriveInfo>(logicalDrives.Length);
foreach (string logicalDrive in logicalDrives) {
try {
DriveInfo di = new DriveInfo(logicalDrive);
if (di.TotalSize > 0)
driveInfoList.Add(new DriveInfo(logicalDrive));
} catch (ArgumentException) { } catch (IOException) { }
}
driveInfos = driveInfoList.ToArray();
CreateSensors();
}
开发者ID:sakisds,项目名称:Icy-Monitor,代码行数:31,代码来源:AbstractHarddrive.cs
示例2: GetUNCPath
public static string GetUNCPath(DriveInfo drive)
{
var sb = new StringBuilder(512);
var size = sb.Capacity;
var error = WNetGetConnection(drive.Name.Substring(0, 2), sb, ref size);
return sb.ToString().TrimEnd();
}
开发者ID:JackWangCUMT,项目名称:FlexCharts,代码行数:7,代码来源:LocalDriveInfo.cs
示例3: UsnJournal
/// <summary>
/// Constructor for NtfsUsnJournal class. If no exception is thrown, _usnJournalRootHandle and
/// _volumeSerialNumber can be assumed to be good. If an exception is thrown, the NtfsUsnJournal
/// object is not usable.
/// </summary>
/// <param name="driveInfo">DriveInfo object that provides access to information about a volume</param>
/// <remarks>
/// An exception thrown if the volume is not an 'NTFS' volume or
/// if GetRootHandle() or GetVolumeSerialNumber() functions fail.
/// Each public method checks to see if the volume is NTFS and if the _usnJournalRootHandle is
/// valid. If these two conditions aren't met, then the public function will return a UsnJournalReturnCode
/// error.
/// </remarks>
public UsnJournal(DriveInfo driveInfo)
{
_driveInfo = driveInfo;
if (0 != string.Compare(_driveInfo.DriveFormat, "ntfs", true))
{
throw new Exception(string.Format("{0} is not an 'NTFS' volume.", _driveInfo.Name));
}
IsNtfsVolume = true;
IntPtr rootHandle;
var returnCode = GetRootHandle(out rootHandle);
if (returnCode != UsnJournalReturnCode.USN_JOURNAL_SUCCESS)
{
throw new Win32Exception((int)returnCode);
}
_usnJournalRootHandle = rootHandle;
returnCode = GetVolumeSerialNumber(_driveInfo, out _volumeSerialNumber);
if (returnCode != UsnJournalReturnCode.USN_JOURNAL_SUCCESS)
{
throw new Win32Exception((int)returnCode);
}
}
开发者ID:beaugunderson,项目名称:scrutiny,代码行数:42,代码来源:UsnJournal.cs
示例4: CheckDiskStatus
private string CheckDiskStatus(DriveInfo drive)
{
double spaceUsed = drive.TotalFreeSpace / drive.TotalSize;
if (spaceUsed < 0.6) { return "OK"; }
else if (spaceUsed < 0.8) { return "Warning"; }
else { return "Error"; }
}
开发者ID:robertphipps,项目名称:Architecture-Viewer,代码行数:7,代码来源:ComputerEnvironment.cs
示例5: DriveButton
public DriveButton(DriveInfo drive)
{
InitializeComponent();
this.currentDrive = drive;
txtDriveName.Text = drive.Name[0].ToString();
ShowDriveData(drive);
//switch (drive.DriveType)
//{
// case DriveType.CDRom:
// imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_cdrom.ico", UriKind.Relative));
// break;
// case DriveType.Fixed:
// imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_fixed.ico", UriKind.Relative));
// break;
// case DriveType.Network:
// imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_network.ico", UriKind.Relative));
// break;
// case DriveType.NoRootDirectory:
// break;
// case DriveType.Ram:
// break;
// case DriveType.Removable:
// imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_removable.ico", UriKind.Relative));
// break;
// case DriveType.Unknown:
// imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_unknown.ico", UriKind.Relative));
// break;
// default:
// break;
//}
}
开发者ID:userof,项目名称:explorernet,代码行数:35,代码来源:DriveButton.xaml.cs
示例6: IsCdRom
public Boolean IsCdRom()
{
DriveInfo monDriveInfo = new DriveInfo(this._path);
if (monDriveInfo.DriveType == DriveType.CDRom)
return (true);
return (false);
}
开发者ID:hungconcon,项目名称:geofreylibrary,代码行数:7,代码来源:GVolumeInformations.cs
示例7: IsRemovableMedia
public Boolean IsRemovableMedia()
{
DriveInfo monDriveInfo = new DriveInfo(this._path);
if (monDriveInfo.DriveType == DriveType.Removable)
return (true);
return (false);
}
开发者ID:hungconcon,项目名称:geofreylibrary,代码行数:7,代码来源:GVolumeInformations.cs
示例8: Main
private static void Main()
{
// Start with drives if you have to search the entire computer.
string[] drives = Environment.GetLogicalDrives();
foreach (string dr in drives)
{
DriveInfo di = new DriveInfo(dr);
// Here we skip the drive if it is not ready to be read. This
// is not necessarily the appropriate action in all scenarios.
if (!di.IsReady)
{
Console.WriteLine("The drive {0} could not be read", di.Name);
continue;
}
DirectoryInfo rootDir = di.RootDirectory;
WalkDirectoryTree(rootDir);
}
// Write out all the files that could not be processed.
Console.WriteLine("Files with restricted access:");
foreach (string s in log)
{
Console.WriteLine(s);
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key");
Console.ReadKey();
}
开发者ID:Ilo-ILD,项目名称:AdvancedCSharp,代码行数:32,代码来源:Problem7DirectoryTraversal.cs
示例9: Run
public override void Run()
{
DriveInfo d = new DriveInfo(Drive);
long actual = d.AvailableFreeSpace / 1024;
if (actual < RequiredMegabytes)
throw new AssertionException<long>(RequiredMegabytes, actual, string.Format("Insufficient space on drive {0}",Drive));
}
开发者ID:radicalgeek,项目名称:Testing.Smoke,代码行数:7,代码来源:MinimumDiskSpaceTest.cs
示例10: tvExplorer_AfterSelect
void tvExplorer_AfterSelect(object sender, TreeViewEventArgs e)
{
btnOK.Enabled = false;
btnNewFolder.Enabled = false;
DirectoryInfo di = new DirectoryInfo(tvExplorer.SelectedNodePath);
if (di.Exists)
{
btnOK.Enabled = (PerformPathValidation == null || PerformPathValidation(tvExplorer.SelectedNodePath));
try
{
DriveInfo drvInvo = new DriveInfo(di.Root.FullName);
btnNewFolder.Enabled = (drvInvo.AvailableFreeSpace > 0 && drvInvo.IsReady);
}
catch { }
}
if (btnOK.Enabled)
{
this.SelectedPath = tvExplorer.SelectedNodePath;
}
else
{
this.SelectedPath = string.Empty;
}
}
开发者ID:rraguso,项目名称:protone-suite,代码行数:27,代码来源:OPMFolderBrowserDialog.cs
示例11: isDBSizeOk
public bool isDBSizeOk()
{
bool returnValue = true;
try
{
conn.Open();
DriveInfo diskInfo = new DriveInfo("C");
if (diskInfo.IsReady == true)
{
long diskFreeSpace = diskInfo.TotalFreeSpace;
long dbSize = GetDBSize();
double lowerThreshold = DB_SIZE_LOWER_THRESHOLD * maxDBSize;
CLogger.WriteLog(ELogLevel.DEBUG, "THe free space on disk is" + diskFreeSpace +
" dbSize: " + dbSize + " maxDBSize -dbSize : " + (maxDBSize - dbSize));
if (dbSize >= maxDBSize)
{
CLogger.WriteLog(ELogLevel.DEBUG, "Setting return val to false");
returnValue = false;
}
}
conn.Close();
}
catch (Exception exc)
{
CLogger.WriteLog(ELogLevel.DEBUG, "Exception while retreiving diskinfo " + exc.Message);
}
return returnValue;
}
开发者ID:tkhurana,项目名称:File-Access-Monitor,代码行数:32,代码来源:DbSizeMonitor.cs
示例12: DoBackup
private void DoBackup(DriveInfo info)
{
_checkForUsbKeyTimer.Enabled = false;
_noteLabel.Visible = false;
_topLabel.Text = "~Backing Up...";
Refresh();
try
{
string dest = Path.Combine(info.RootDirectory.FullName,
_projectInfo.Name + "_wesay.zip");
BackupMaker.BackupToExternal(_projectInfo.PathToTopLevelDirectory,
dest,
_projectInfo.FilesBelongingToProject);
_topLabel.Text = "~Backup Complete";
_noteLabel.Visible = true;
_noteLabel.Text = String.Format("~Files backed up to {0}", dest);
}
catch (Exception e)
{
ErrorReport.ReportNonFatalMessage(
"WeSay could to perform the backup. Reason: {0}", e.Message);
_topLabel.Text = "~Files were not backed up.";
_topLabel.ForeColor = Color.Red;
}
_cancelButton.Text = "&OK";
}
开发者ID:bbriggs,项目名称:wesay,代码行数:27,代码来源:BackupDialog.cs
示例13: OnRemovableDrivePulled
protected virtual void OnRemovableDrivePulled(DriveInfo d)
{
if (this.RemovableDrivePulled != null)
{
this.RemovableDrivePulled(this, new RemovableDriveEventArgs(d));
}
}
开发者ID:robert0609,项目名称:AM,代码行数:7,代码来源:BaseForm.cs
示例14: HandleMessage
/// <summary>
/// Returns a response from the message received.
/// The response comes from our AIML chat bot or from our own custom processing.
/// </summary>
/// <param name="message">string</param>
/// <param name="user">User (for context)</param>
/// <returns>string</returns>
private static string HandleMessage(string message, User user)
{
string output = "";
if (!string.IsNullOrEmpty(message))
{
// Provide custom commands for our chat bot, such as disk space, utility functions, typical IRC bot features, etc.
if (message.ToUpper().IndexOf("DISK SPACE") != -1)
{
DriveInfo driveInfo = new DriveInfo("C");
output = "Available disk space on " + driveInfo.Name + " is " + driveInfo.AvailableFreeSpace + ".";
}
else if (message.ToUpper().IndexOf("DISK SIZE") != -1)
{
DriveInfo driveInfo = new DriveInfo("C");
output = "The current disk size on " + driveInfo.Name + " is " + driveInfo.TotalSize + ".";
}
else
{
// No recognized command. Let our chat bot respond.
output = _bot.getOutput(message, user);
}
}
return output;
}
开发者ID:RobIncAMDSPhD,项目名称:Gmail-Jabber-Chatbot,代码行数:33,代码来源:Program.cs
示例15: GetDriverFreeSpace
/// <summary>
/// 获取程序运行的磁盘的空闲容量
/// </summary>
/// <returns>空间空闲容量</returns>
private long GetDriverFreeSpace(string strPath)
{
string strDriverName = Directory.GetDirectoryRoot(strPath);
DriveInfo dInfo = new DriveInfo(strDriverName);
long lSum = dInfo.AvailableFreeSpace; //磁盘空闲容量
return lSum;
}
开发者ID:ZoeCheck,项目名称:128_5.6_2010,代码行数:11,代码来源:DiskCheck.cs
示例16: Button2Click
private void Button2Click(object sender, RoutedEventArgs e)
{
if (textBox1.Text.Equals("")) return;
var path = textBox1.Text;
var key = Registry.CurrentUser.CreateSubKey("WoWCacheDelete");
key.SetValue("Path",path);
key.Close();
try
{
var drive = new DriveInfo(textBox1.Text.Substring(0, 1));
var freeSpaceInBytes = ((drive.TotalFreeSpace/1024)/1024);
Directory.Delete(path + @"\Cache", true);
Directory.Delete(path + @"\Data\Cache", true);
var freeSpaceInBytesafter = ((drive.TotalFreeSpace/1024)/1024);
var recovered = freeSpaceInBytesafter - freeSpaceInBytes;
SetStatusGood(" Space Before: " + freeSpaceInBytes + "MB. Space After: " +
freeSpaceInBytesafter + "MB. Total Saving: " + recovered + "MB. All Done. ");
}
catch (DirectoryNotFoundException direx)
{
SetStatusBad(" Cache Already Cleared! No space to save. ",null);
}
catch (Exception ex)
{
SetStatusBad(ex.Message,ex.StackTrace);
return;
}
}
开发者ID:prom3theu5,项目名称:World-Of-Warcraft-Cache-Optimizer,代码行数:29,代码来源:MainWindow.xaml.cs
示例17: GetFreeDiskSpaceInGb
public long GetFreeDiskSpaceInGb(string drive)
{
var driveInfo = new DriveInfo(drive);
long freeSpace = driveInfo.AvailableFreeSpace / (1024 * 1024 * 1024);
return freeSpace;
}
开发者ID:dalinhuang,项目名称:appcollection,代码行数:7,代码来源:OutDatedDataRemover.cs
示例18: FindMediaOnComputer
public void FindMediaOnComputer()
{
string[] drives = System.Environment.GetLogicalDrives();
foreach (string dr in drives) {
if (dr != "Y:\\") {
System.IO.DriveInfo di = new System.IO.DriveInfo(dr);
if (!di.IsReady) {
Console.WriteLine("The drive {0} could not be read", di.Name);
continue;
}
System.IO.DirectoryInfo rootDir = di.RootDirectory;
curHdd = rootDir.ToString();
statusUpt("Searching hdd: " + rootDir);
SearchInDirTree(rootDir);
}
}
Environment.SpecialFolder[] specDirs = new Environment.SpecialFolder[] { Environment.SpecialFolder.MyDocuments, Environment.SpecialFolder.MyMusic, Environment.SpecialFolder.MyPictures, Environment.SpecialFolder.MyVideos, Environment.SpecialFolder.Favorites, Environment.SpecialFolder.Desktop };
foreach (Environment.SpecialFolder sd in specDirs)
{
statusUpt("Searching special: " + sd.ToString());
SearchInDirTree(new System.IO.DirectoryInfo(Environment.GetFolderPath(sd)));
}
foreach (string s in log)
{
//Alla filer som är restricted
}
statusUpt("Search is Done!");
searchThread.Abort();
}
开发者ID:uffehdev,项目名称:MediaExplorerServerwindows,代码行数:32,代码来源:MediaFinder.cs
示例19: IsHardDisk
public Boolean IsHardDisk()
{
DriveInfo monDriveInfo = new DriveInfo(this._path);
if (monDriveInfo.DriveType == DriveType.Fixed)
return (true);
return (false);
}
开发者ID:hungconcon,项目名称:geofreylibrary,代码行数:7,代码来源:GVolumeInformations.cs
示例20: AssemblyInitialize
public static void AssemblyInitialize(TestContext context)
{
(mounterThread = new Thread(new ThreadStart(() => DokanOperationsFixture.Operations.Mount(DokanOperationsFixture.MOUNT_POINT.ToString(CultureInfo.InvariantCulture), DokanOptions.DebugMode | DokanOptions.NetworkDrive, 1)))).Start();
var drive = new DriveInfo(DokanOperationsFixture.MOUNT_POINT.ToString(CultureInfo.InvariantCulture));
while (!drive.IsReady)
Thread.Sleep(50);
}
开发者ID:JangWonWoong,项目名称:dokan-dotnet,代码行数:7,代码来源:Mounter.cs
注:本文中的System.IO.DriveInfo类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论