最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#將指定目錄所有文件名轉換成小寫的方法

 更新時間:2015年04月17日 15:38:17   作者:work24  
這篇文章主要介紹了C#將指定目錄所有文件名轉換成小寫的方法,涉及C#中目錄的遍歷及filename.ToLowerInvariant方法的使用技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了C#將指定目錄所有文件名轉換成小寫的方法。分享給大家供大家參考。具體如下:

using System;
using System.IO;
using System.Linq;
namespace RobvanderWoude
{
 class LoCase
 {
  static int Main( string[] args )
  {
   string dir = string.Empty;
   string filespec = string.Empty;
   char[] trailingbackslash = "\\".ToCharArray( 0, 1 );
   char[] upcaseletters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray( 0, 26 );
   bool verbose = false;
   #region Command Line Parsing
   switch ( args.Length )
   {
    case 0:
     return WriteError( string.Empty );
    case 1:
     filespec = args[0].Trim( '"' );
     break;
    case 2:
     filespec = args[0].Trim( '"' );
     if ( args[1].Substring( 0, 2 ).ToUpper( ) == "/V" )
     {
      verbose = true;
     }
     else
     {
      return WriteError( "Invalid command line switch: " + args[1] );
     }
     break;
    default:
     return WriteError( string.Empty );
   }
   if ( string.IsNullOrWhiteSpace( filespec ) || filespec == "/?" )
   {
    return WriteError( string.Empty );
   }
   if ( filespec.IndexOfAny( "/?".ToCharArray( 0, 2 ) ) != -1 )
   {
    return WriteError( "Invalid file specification: \"" + filespec + "\"" );
   }
   #endregion Command Line Parsing
   try
   {
    // Check if the directory exists
    try
    {
     dir = Path.GetDirectoryName( filespec );
     if ( string.IsNullOrWhiteSpace( dir ) )
     {
      dir = Path.GetFullPath( "." );
     }
     if ( !Directory.Exists( dir ) )
     {
      return WriteError( "Directory not found: \"" + dir + "\"" );
     }
     dir = dir.TrimEnd( trailingbackslash ) + "\\";
    }
    catch ( ArgumentException )
    {
     return WriteError( "Parent directory not found" );
    }
    // Extract the FILE specification (removing the path)
    string filenames = filespec.Substring( filespec.LastIndexOf( "\\" ) + 1 );
    // Enumerate the files
    string[] files = Directory.EnumerateFiles( dir, filenames ).ToArray<string>( );
    int count = 0;
    foreach ( string file in files )
    {
     if ( File.Exists( file ) )
     {
      string filename = Path.GetFileName( file );
      if ( filename.IndexOfAny( upcaseletters ) > -1 )
      {
       count++;
       string newfilename = dir + filename.ToLowerInvariant( );
       File.Move( file, newfilename );
      }
     }
    }
    if ( verbose )
    {
     Console.WriteLine( "{0} matching file{1} renamed", ( count == 0 ? "No" : count.ToString( ) ), ( count == 1 ? string.Empty : "s" ) );
    }
    return count;
   }
   catch ( Exception e )
   {
    return WriteError( e.Message );
   }
  }
  public static int WriteError( Exception e )
  {
   return WriteError( e == null ? null : e.Message );
  }
  public static int WriteError( string errorMessage )
  {
   if ( !string.IsNullOrWhiteSpace( errorMessage ) )
   {
    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( "LoCase.exe, Version 1.02" );
   Console.Error.WriteLine( "Rename specified files to all lower case" );
   Console.Error.WriteLine( );
   Console.Error.Write( "Usage: " );
   Console.ForegroundColor = ConsoleColor.White;
   Console.Error.WriteLine( "LoCase.exe filespec [ /Verbose ]" );
   Console.ResetColor( );
   Console.Error.WriteLine( );
   Console.Error.Write( "Where: " );
   Console.ForegroundColor = ConsoleColor.White;
   Console.Error.Write( "filespec" );
   Console.ResetColor( );
   Console.Error.WriteLine( " is (are) the file(s) to be renamed (wildcards allowed)" );
   Console.ForegroundColor = ConsoleColor.White;
   Console.Error.Write( "   /V" );
   Console.ResetColor( );
   Console.Error.WriteLine( "erbose displays the number of files renamed" );
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Note:  Use doublequotes if filespec contains spaces." );
   Console.Error.WriteLine( "   Return code (\"ErrorLevel\") equals the number of renamed files." );
   Console.Error.Write( "   Switch may be abbreviated, e.g. " );
   Console.ForegroundColor = ConsoleColor.White;
   Console.Error.Write( "/V" );
   Console.ResetColor( );
   Console.Error.Write( " instead of " );
   Console.ForegroundColor = ConsoleColor.White;
   Console.Error.Write( "/V" );
   Console.ResetColor( );
   Console.Error.WriteLine( "erbose." );
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Written by Rob van der Woude" );
   return 0;
  }
 }
}

希望本文所述對大家的C#程序設計有所幫助。

相關文章

  • unity中實現(xiàn)Edge瀏覽器鼠標手勢的功能思路詳解

    unity中實現(xiàn)Edge瀏覽器鼠標手勢的功能思路詳解

    這篇文章主要介紹了unity中實現(xiàn)Edge瀏覽器鼠標手勢的功能思路詳解,實現(xiàn)起來其實并不復雜,涉及的技術點有pc端和移動端屏幕拖動事件,二維向量的相關運算,手勢匹配算法,事件系統(tǒng)設計模式,需要的朋友可以參考下
    2023-12-12
  • C# 實現(xiàn)在當前目錄基礎上找到上一層目錄

    C# 實現(xiàn)在當前目錄基礎上找到上一層目錄

    這篇文章主要介紹了C# 實現(xiàn)在當前目錄基礎上找到上一層目錄,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • C#實現(xiàn)Winform版計算器

    C#實現(xiàn)Winform版計算器

    這篇文章主要為大家詳細介紹了C#實現(xiàn)Winform版計算器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • C#面向對象設計的七大原則

    C#面向對象設計的七大原則

    這篇文章主要為大家詳細介紹了C#面向對象設計的七大原則,未讀文章之前大家說一說都有哪七大原則,是不是七大原則都可以全部列出,想要了解的朋友可以參考一下
    2016-05-05
  • C# 使用 log4net 日志組件的方法

    C# 使用 log4net 日志組件的方法

    這篇文章主要介紹了C# 使用 log4net 日志組件的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • c#使用簡單工廠模式實現(xiàn)生成html文件的封裝類分享

    c#使用簡單工廠模式實現(xiàn)生成html文件的封裝類分享

    這篇文章主要介紹了運用了簡單工廠模式實現(xiàn)頁面靜態(tài)化封裝類,思路比較簡單,大家可根據(jù)自己的思路再擴展此類
    2014-01-01
  • C# 獲取當前月份天數(shù)的三種方法總結

    C# 獲取當前月份天數(shù)的三種方法總結

    本篇文章主要是對C#中獲取目前月份的天數(shù)的三種方法進行了詳細的總結介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • C#窗體全屏功能實例代碼

    C#窗體全屏功能實例代碼

    簡要介紹窗體全屏的方法,列出實現(xiàn)窗體的全屏功能以及全屏功能的快捷鍵的代碼,需要的朋友可以參考下
    2016-11-11
  • c#基于NVelocity實現(xiàn)代碼生成

    c#基于NVelocity實現(xiàn)代碼生成

    這篇文章主要介紹了c#基于NVelocity實現(xiàn)代碼生成的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2021-01-01
  • C#中常見的系統(tǒng)內置委托用法詳解

    C#中常見的系統(tǒng)內置委托用法詳解

    這篇文章主要介紹了C#中常見的系統(tǒng)內置委托用法,主要包括了Action類的委托、Func類的委托、Predicate<T>委托、Comparison<T>委托等,需要的朋友可以參考下
    2014-09-09

最新評論

成安县| 乐至县| 大余县| 巴里| 新晃| 林州市| 华阴市| 福安市| 定安县| 柯坪县| 海兴县| 察哈| 宜昌市| 稻城县| 柳江县| 红河县| 马关县| 张家界市| 吉隆县| 景东| 安顺市| 株洲市| 平和县| 高台县| 曲靖市| 册亨县| 黑龙江省| 时尚| 海口市| 宣武区| 阳江市| 连江县| 宽城| 江都市| 旬阳县| 芜湖县| 甘泉县| 正镶白旗| 德庆县| 罗城| 称多县|