Skip to content

Commit

Permalink
rename all script
Browse files Browse the repository at this point in the history
  • Loading branch information
jurczewski committed Jun 30, 2024
1 parent 07897f4 commit a4be84e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A minimal .NET 8 template

1. Create a new repository using this template
2. Replace `ProjectName` with your project name
- If your are on Windows, use [rename-all.ps1](./rename-all.ps1) Powershell Script

## ⚗️ Features

Expand Down
47 changes: 47 additions & 0 deletions rename-all.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Function to replace "HousingScraper" in file content and filenames with the given phrase
function Replace-FilenameAndContent {
param (
[string]$NewPhrase
)

# Get the current directory
$Directory = Get-Location

# Get all files in the current directory and subdirectories
$files = Get-ChildItem -Path $Directory -File -Recurse

foreach ($file in $files) {
# Replace "HousingScraper" with the new phrase in the file content
try {
$content = Get-Content -Path $file.FullName -ErrorAction Stop
$newContent = $content -replace "HousingScraper", $NewPhrase
Set-Content -Path $file.FullName -Value $newContent
Write-Host "Replaced content in '$($file.Name)'"
}
catch {
Write-Warning "Could not read or write content of '$($file.FullName)'. Skipping content replacement."
}
}

# Renaming files after content replacement
foreach ($file in $files) {
# Check if the filename contains "HousingScraper"
if ($file.Name -like "*HousingScraper*") {
# Replace "HousingScraper" with the new phrase in the filename
$newName = $file.Name -replace "HousingScraper", $NewPhrase

# Get the full path of the new filename
$newPath = Join-Path -Path $file.DirectoryName -ChildPath $newName

# Rename the file
Rename-Item -Path $file.FullName -NewName $newPath
Write-Host "Renamed '$($file.Name)' to '$($newName)'"
}
}
}

# Prompt the user for the new phrase
$newPhrase = Read-Host "Enter the new phrase to replace 'HousingScraper'"

# Call the function to replace filenames and file content
Replace-FilenameAndContent -NewPhrase $newPhrase

0 comments on commit a4be84e

Please sign in to comment.