Skip to content

Instantly share code, notes, and snippets.

@Guiorgy
Created March 19, 2024 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Guiorgy/508e804ff3c174fef9f55ad7f254725c to your computer and use it in GitHub Desktop.
Save Guiorgy/508e804ff3c174fef9f55ad7f254725c to your computer and use it in GitHub Desktop.
Appends a GPLv3 liecense notice to the top of every C# source file
$comment = @"
/*
This file is part of [PROJECT] (Copyright © [YEAR] [AUTHOR]).
[PROJECT] is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
[PROJECT] is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Foobar. If not, see <https://www.gnu.org/licenses/>.
*/
"@
$files = Get-ChildItem -Path . -Filter *.cs -Recurse
foreach ($file in $files) {
# Read the content of the file
$content = [System.IO.File]::ReadAllText($file.FullName)
# Prepend the comment to the content
$newContent = $comment + $content
# Create a StreamWriter with UTF8 encoding (no BOM)
$streamWriter = New-Object System.IO.StreamWriter($file.FullName, $false, [System.Text.Encoding]::UTF8)
# Write the new content back to the file using the StreamWriter
$streamWriter.Write($newContent)
# Close the StreamWriter
$streamWriter.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment