Created
December 25, 2021 14:49
-
-
Save stevencohn/9b059a0b701eda193da7c104abd7f8f7 to your computer and use it in GitHub Desktop.
Remove all #region and #endregion lines from all *.cs files under a root folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
// remove all occurances of #region and #endregion from CS files under a root folder | |
var root = @"C:\Users\steve\Downloads\System_Windows_Forms_Calendar_003"; | |
var files = Directory.EnumerateFiles(root, "*.cs", SearchOption.AllDirectories); | |
if (files.Any()) | |
{ | |
var regex = new Regex(@"^\s*#(?:end)?region.*$"); | |
foreach (var path in files) | |
{ | |
path.Dump(); | |
var lines = File.ReadAllLines(path); | |
File.WriteAllLines(path, lines.Where(l => !regex.Match(l).Success)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can pasted into LINQPad. Change the root variable to point to the folder containing source code. It will look for all *.cs files under that folder and remove all #region and #endregion lines from every file