C#判断指定驱动器是否是Fat分区格式的方法
2015-04-18 12:39
876 查看
本文实例讲述了C#判断指定驱动器是否是Fat分区格式的方法。分享给大家供大家参考。具体如下:
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#程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- C#判断指定分区是否是ntfs格式的方法
- C#判断指定驱动器是否已经准备就绪的方法
- C#判断指定文件是否是只读的方法
- C#获取FTP目录下文件夹、文件的方法,进而判断FTP下指定文件夹是否存在
- C#用于网络通信时预先判断到指定IP是否畅通方法
- C#、vb.net及SQL判断指定年份是否为闰年的方法
- C#判断给定IP地址是否在指定范围内的方法
- C#判断网络地址 Url 是否存在的方法
- php判断数组中是否存在指定键(key)的方法
- C#中判断socket是否已断开的方法
- c#判断字符是否为中文的三种方法分享(正则表达式判断)
- C#判断文件是否存在方法
- C#中判断socket是否已断开的方法
- C#中检测某个类(方法、程序集等各种部分)是否应用了指定的特性以及对特性的一些简单操作
- C# 判断两张图片是否一致的快速方法
- 【最简单的方法】js判断字符串是否为JSON格式(20180115更新)
- c#简单判断是否是闰年的方法代码
- C#判断字符串是否是满足指定位数的小数或整数
- C#利用反射来判断对象是否包含某个属性的实现方法
- 黄聪:C#中HtmlAgilityPack判断是否包含或不包含指定的属性或值