-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07897f4
commit a4be84e
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
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
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 |