C# 查找文件夹下的文件,进行重命名
private void rename() { var path = @"E:\code\LIMS\UI设计稿\UI设计\icon\图标(3)\图标\\"; DirectoryInfo directory = new DirectoryInfo(path); var dirs = directory.GetDirectories(); foreach (var item in dirs) { // DirectoryInfo dir = new DirectoryInfo(item); var zidirs = item.GetDirectories();//取得选中与未选中的目录 foreach (var zidir in zidirs) { var name = zidir.Name; if (name.Equals("未选中")) { reFileName(zidir,false); } else if (name.Equals("选中")) { reFileName(zidir, true); } } } } private void reFileName(DirectoryInfo directoryInfo,bool isSelect = true) { var files = directoryInfo.GetFiles(); var changeN = isSelect ? "B":"A"; foreach (var item in files) { System.Diagnostics.Debug.WriteLine(item.Name); System.Diagnostics.Debug.WriteLine(item.FullName); if (item.Name.EndsWith(".svg") && item.Name.Contains("@3x")) { var name = item.Name.Replace("@3x", changeN); FileSystem.RenameFile(item.FullName, name); } } } }
大道三千,条条皆可证道。道心不可失。