C#判断指定分区是否是ntfs格式的方法
2015-04-18 12:31
1316 查看
本文实例讲述了C#判断指定分区是否是ntfs格式的方法。分享给大家供大家参考。具体如下:
using System; using System.IO; namespace RobvanderWoude { class IsNTFS { 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 == "NTFS" ) { 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( "IsNTFS, Version 1.00" ); Console.Error.WriteLine( "Return 'errorlevel' 0 if the specified drive is NTFS 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 NTFS, 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#判断指定驱动器是否是Fat分区格式的方法
- C#判断给定IP地址是否在指定范围内的方法
- C#获取FTP目录下文件夹、文件的方法,进而判断FTP下指定文件夹是否存在
- C#判断指定文件是否是只读的方法
- C#判断指定驱动器是否已经准备就绪的方法
- C#用于网络通信时预先判断到指定IP是否畅通方法
- C#、vb.net及SQL判断指定年份是否为闰年的方法
- JavaScript判断数组是否包含指定元素的方法
- C#获取真实IP地址(IP转为长整形、判断是否内网IP的方法)
- C#判断程序是否是管理员权限运行的方法代码示例
- C#判断字符串是否为空的三种方法及其比较
- C#+AE 判断点是否在面内的方法
- C#/asp.net 正则表达式 判断邮件格式- -判断是否为数字
- C#服务端判断客户端socket是否已断开的方法
- 判断输入的字符串是否是日期格式的简单方法
- List.contains方法——判断列表中是否包含指定元素
- C#判断一个类中有无"指定名称"的方法
- C#中判断字符串是否中文的方法
- php判断是否为json格式的方法
- containsKey方法——判断是否包含指定的键名