array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } 111string(0) "" int(1) int(10) int(70) int(8640000) string(13) "likecs_art_db" array(1) { ["query"]=> array(1) { ["match_all"]=> object(stdClass)#29 (0) { } } } array(1) { ["createtime.keyword"]=> array(1) { ["order"]=> string(4) "desc" } } int(10) int(0) int(8640000) array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } 批量改文件名小工具 - 爱码网

有时候需要批量替换一个文件夹下面所有文件的名称,如果文件太多,就没办法手工一个一个来改了。

想想作为程序员十几分钟就可以搞定的东西,解决别人几个小时工作,岂不快哉。

于是有此工具发表,界面如下:

批量改文件名小工具

 

程序下载

 

核心代码就20多行

 1 Computer MyComputer = new Computer();
 2         int totalReplace = 0;
 3         //递归调用
 4         private void DoReplace(string dir, bool includeChild)
 5         {
 6             DirectoryInfo di = new DirectoryInfo(dir);
 7             FileInfo[] files = di.GetFiles();
 8             if (files.Length > 0)
 9             {
10                 foreach (FileInfo f in files)
11                 {
12                     string newFileName = f.Name.Replace(txtOld.Text, txtRep.Text);
13                     if(f.Name!=newFileName)
14                     {
15                         MyComputer.FileSystem.RenameFile(f.FullName, newFileName);
16                         totalReplace++;
17                     }
18                 }
19             }
20 
21             DirectoryInfo[] dirs= di.GetDirectories();
22             if (dirs.Length > 0)
23             {
24                 foreach (DirectoryInfo d in dirs)
25                 {
26                     DoReplace(d.FullName, includeChild);
27                 }
28             }
29         }

 

相关文章: