注释掉项目中所有*.cs

作者:追风剑情 发布于:2021-7-8 11:55 分类:C#

  1. using System.Text;
  2. using System.IO;
  3.  
  4. namespace ConsoleApp1
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. CommonCSFile();
  11. }
  12.  
  13. //注释掉所有*.cs文件
  14. private static void CommonCSFile()
  15. {
  16. //项目代码所在目录
  17. string src = @"D:\Scripts";
  18. StringBuilder sb = new StringBuilder();
  19. DirectoryInfo Dir = new DirectoryInfo(src);
  20. //递归遍历所有目录
  21. foreach (FileInfo f in Dir.GetFiles("*.cs", SearchOption.AllDirectories)) //查找所有文件
  22. {
  23. var fr = f.OpenText();
  24. string content = fr.ReadToEnd();
  25. sb.AppendLine("#if false");
  26. sb.AppendLine(content);
  27. sb.AppendLine("#endif");
  28. fr.Close();
  29.  
  30. var fw = f.CreateText();
  31. fw.Write(sb.ToString());
  32. fw.Flush();
  33. fw.Close();
  34.  
  35. sb.Clear();
  36. }
  37. }
  38. }
  39. }

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号