The program uses regular expressions to make text replacement, and the breadth priority is a lot of life (basic knowledge is important), solving problems that cannot be replaced back-wrap Class ReplaceE {////
/ param> /// String param> /// String param> /// that the backup files param> /// whether to acquire subfolders param> public static void TravelReplace (string path, string replacedStr, string findPattern, bool isBackup, bool isGetSubFloder) {Queue queue = new Queue (); DirectoryInfo di = null; string subPath = string.Empty; string currentPath = string.Empty; FileSystemInfo [] dirs = null; queue.Enqueue (path); while (queue.Count > 0) {currentPath = (string) queue.Dequeue (); di = new DirectoryInfo (currentPath); // get files under current directiory FileSystemInfo [] files = di.GetFiles ( "* sql."); foreach (FileSystemInfo f in files) {doReplace (f.FullName, replacedStr, findPattern, isBackup);} // Get only subdirectories if (isGetSubFloder == true) {dirs = di.GetDirectories (); foreach (FileSystemInfo d in dirs) {subPath = d .Fullna Me; Queue.enqueue (Subpath); console.writeline (subpath);}}}}} test: Replacee.travelReplace (@ "E: / TEMP / TTT", "/ R / N);", @ "(/ @" R / n) {2,} /); "True, true);