C#判斷指定驅(qū)動器是否是Fat分區(qū)格式的方法
更新時間:2015年04月18日 12:39:23 作者:work24
這篇文章主要介紹了C#判斷指定驅(qū)動器是否是Fat分區(qū)格式的方法,涉及C#中DriveFormat屬性的使用技巧,非常具有實(shí)用價值,需要的朋友可以參考下
本文實(shí)例講述了C#判斷指定驅(qū)動器是否是Fat分區(qū)格式的方法。分享給大家供大家參考。具體如下:
using System;
using System.IO;
namespace RobvanderWoude
{
class IsFAT
{
public static int Main( string[] args )
{
try
{
if ( args.Length == 0 )
{
return WriteError( string.Empty );
}
if ( args.Length > 1 )
{
return WriteError( "Invalid number of arguments." );
}
string drive = args[0].ToUpper( );
DriveInfo[] allDrives = DriveInfo.GetDrives( );
foreach ( DriveInfo drv in allDrives )
{
if ( drive == drv.Name.Substring( 0, 2 ) )
{
if ( drv.IsReady )
{
Console.WriteLine( drv.DriveFormat.ToUpper( ) );
if (drv.DriveFormat == "FAT" || drv.DriveFormat == "FAT32")
{
return 0;
}
else
{
return 2;
}
}
else
{
Console.WriteLine(drv.DriveType.ToString().ToUpper());
return 1;
}
}
}
return WriteError( "Invalid drive specification." );
}
catch ( Exception e )
{
// Display help text with error message
return WriteError( e );
}
}
// Code to display help and optional error message,
//by Bas van der Woude
public static int WriteError( Exception e )
{
return WriteError( e == null ? null : e.Message );
}
public static int WriteError( string errorMessage )
{
string fullpath = Environment.GetCommandLineArgs().GetValue(0).ToString();
string[] program = fullpath.Split( '\\' );
string exeName = program[program.GetUpperBound(0)];
exeName = exeName.Substring(0, exeName.IndexOf('.'));
if ( string.IsNullOrEmpty( errorMessage ) == false )
{
Console.Error.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.Write( "ERROR: " );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( errorMessage );
Console.ResetColor();
}
Console.Error.WriteLine();
Console.Error.WriteLine("IsFAT, Version 1.00");
Console.Error.WriteLine("Return 'errorlevel' 0 if the specified drive is FAT or FAT32 formated");
Console.Error.WriteLine();
Console.Error.Write("Usage: ");
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine("{0} drive:", exeName.ToUpper());
Console.ResetColor( );
Console.Error.WriteLine();
Console.Error.WriteLine("Note: Returns 0 if FAT or FAT32, 2 if not, 1 if not ready or invalid.");
Console.Error.WriteLine();
Console.Error.WriteLine("Written by Rob van der Woude");
return 1;
}
}
}
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
深入Resource實(shí)現(xiàn)多語言支持的應(yīng)用詳解
本篇文章是對Resource實(shí)現(xiàn)多語言支持的應(yīng)用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C#實(shí)現(xiàn)的三種模擬自動登錄和提交POST信息的方法
這篇文章主要介紹了C#實(shí)現(xiàn)的三種模擬自動登錄和提交POST信息的方法,分別列舉了WebBrowser、WebClient及HttpWebRequest實(shí)現(xiàn)自動登錄及提交POST的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11
C# 4.0 大數(shù)的運(yùn)算--BigInteger的應(yīng)用詳解
本篇文章是對C# 4.0 大數(shù)的運(yùn)算 BigInteger的應(yīng)用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Visual Studio C#創(chuàng)建windows服務(wù)程序
用Visual C#創(chuàng)建Windows服務(wù)不是一件困難的事,本文就將指導(dǎo)你一步一步創(chuàng)建一個Windows服務(wù)并使用它,本文主要介紹了Visual Studio C#創(chuàng)建windows服務(wù)程序,感興趣的可以了解一下2024-01-01
C#中標(biāo)準(zhǔn)的IDispose模式代碼詳解
在本篇文章中小編給大家分享的是關(guān)于C#中標(biāo)準(zhǔn)的IDispose模式的實(shí)例用法相關(guān)內(nèi)容,有需要的朋友們測試下。2019-09-09

