批量重命名文件

批量重命名文件

下述代码用于批量重命名文件。留作备用。

 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 }

 

posted @ 2016-05-02 20:15  BIT祝威  阅读(912)  评论(0编辑  收藏  举报
canvas start.

canvas end.