批量重命名文件
下述代码用于批量重命名文件。留作备用。
1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace ConsoleApplication1 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 Console.WriteLine("Working..."); 15 string[] filenames = System.IO.Directory.GetFiles(".", "*.*", System.IO.SearchOption.AllDirectories); 16 foreach (var item in filenames) 17 { 18 FileInfo fileInfo = new FileInfo(item); 19 var newName = fileInfo.Name.Replace("ModernRenderer", "Renderer"); 20 21 if (newName != fileInfo.Name) 22 { 23 Console.WriteLine(item); 24 System.IO.File.Move(item, Path.Combine(fileInfo.DirectoryName, newName)); 25 } 26 } 27 28 Console.WriteLine("Done"); 29 Console.ReadKey(); 30 } 31 } 32 }
来源:http://www.cnblogs.com/bitzhuwei/p/rename-files.html