code_junkie

Adding the same comment to every code file in a Visual Studio solution

Nov 13th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. # Process all .cpp and .h files under the directory tree at $PROJECTROOT
  2. # To add other file types, add more "-o -name *.ext" clauses.
  3. # $COPYRIGHTFILE is the file containing your copyright message
  4. COPYRIGHTLENGTH=$(wc -l $COPYRIGHTFILE)
  5. for file in $(find $PROJECTROOT -name *.cpp -o -name *.h); do
  6. if diff <(head -n $COPYRIGHTLENGTH $file) $COPYRIGHTFILE; then
  7. (cat $COPYRIGHTFILE; cat $file) > /tmp/file
  8. mv /tmp/file $file
  9. fi
  10. done
  11.  
  12. 1: static void Main(string[] args)
  13. 2: {
  14. 3: string path = "C:\...TopLevelFolder";
  15. 4: string copyright = "//Copyright © 2011 Rex Cardan, Ph.D";
  16. 5: string[] files = Directory.GetFiles(path, "*.cs",
  17. 6: SearchOption.AllDirectories);
  18. 7: foreach (string file in files)
  19. 8: {
  20. 9: if (file.Split('\')[file.Split('\').Length-1]!= "AssemblyInfo.cs")
  21. 10: {
  22. 11: using (StreamWriter sw = File.AppendText(file))
  23. 12: {
  24. 13: sw.WriteLine("rn");
  25. 14: sw.WriteLine(copyright);
  26. 15: //Normalize Line Endings
  27. 16: sw.WriteLine("rn");
  28. 17: }
  29. 18: }
  30. 19: }
  31. 20: }
Add Comment
Please, Sign In to add comment