-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-copyright.ps1
More file actions
54 lines (41 loc) · 2.16 KB
/
remove-copyright.ps1
File metadata and controls
54 lines (41 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# PowerShell script to find and remove copyright notices from all files
$targetDirectory = "C:\Users\echo_\Code\asciimath"
Set-Location $targetDirectory
Write-Host "Searching for files with copyright notices..." -ForegroundColor Green
# Find files that might contain copyright notices
$searchPatterns = @("copyright", "Copyright", "COPYRIGHT", "©", "(c)", "(C)")
$fileTypes = @("*.py", "*.md", "*.txt", "*.tex", "*.cpp", "*.h", "*.js")
$foundFiles = @()
foreach ($pattern in $searchPatterns) {
foreach ($fileType in $fileTypes) {
$files = Get-ChildItem -Recurse -Include $fileType | Where-Object {
(Get-Content $_.FullName -ErrorAction SilentlyContinue) -match $pattern
}
$foundFiles += $files
}
}
# Remove duplicates
$uniqueFiles = $foundFiles | Sort-Object FullName | Get-Unique -AsString
Write-Host "Found $($uniqueFiles.Count) files with potential copyright notices:" -ForegroundColor Yellow
foreach ($file in $uniqueFiles) {
Write-Host " $($file.FullName)" -ForegroundColor Cyan
# Read file content
$content = Get-Content $file.FullName -Raw
# Remove various copyright patterns
$updatedContent = $content -replace "Copyright.*?\d{4}.*?(\r?\n|$)", ""
$updatedContent = $updatedContent -replace "copyright.*?\d{4}.*?(\r?\n|$)", ""
$updatedContent = $updatedContent -replace "COPYRIGHT.*?\d{4}.*?(\r?\n|$)", ""
$updatedContent = $updatedContent -replace "©.*?\d{4}.*?(\r?\n|$)", ""
$updatedContent = $updatedContent -replace "\(c\).*?\d{4}.*?(\r?\n|$)", ""
$updatedContent = $updatedContent -replace "\(C\).*?\d{4}.*?(\r?\n|$)", ""
# Remove empty lines that might be left behind
$updatedContent = $updatedContent -replace "(\r?\n){3,}", "`n`n"
# Write back only if content changed
if ($content -ne $updatedContent) {
Set-Content -Path $file.FullName -Value $updatedContent.TrimEnd() -NoNewline
Write-Host " Removed copyright notices from $($file.Name)" -ForegroundColor Green
} else {
Write-Host " No copyright changes needed in $($file.Name)" -ForegroundColor Gray
}
}
Write-Host "Finished removing copyright notices." -ForegroundColor Green