Mods Find/Replace text in file

pull/263/head
KnifMelti 2023-01-18 00:53:52 +01:00
parent dd4cc700f2
commit d000abf675
2 changed files with 19 additions and 0 deletions

View File

@ -44,6 +44,15 @@ $DelFile = @("")
$CopyFile = "" $CopyFile = ""
$CopyTo = "" $CopyTo = ""
#Find/Replace text in file
#Example:
#$ModsFile = "C:\dummy.txt"
#$FindText = "brown fox"
#$ReplaceText = "white fox"
$ModsFile = ""
$FindText = ""
$ReplaceText = ""
#Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2" #Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2"
$GrantPath = @("") $GrantPath = @("")
@ -78,6 +87,9 @@ if ($DelFile) {
if ($CopyFile -and $CopyTo) { if ($CopyFile -and $CopyTo) {
Copy-ModsFile $CopyFile $CopyTo Copy-ModsFile $CopyFile $CopyTo
} }
if ($ModsFile -and $FindText -and $ReplaceText) {
Edit-ModsFile $ModsFile $FindText $ReplaceText
}
if ($GrantPath) { if ($GrantPath) {
Grant-ModsPath $GrantPath Grant-ModsPath $GrantPath
} }

View File

@ -192,6 +192,13 @@ function Copy-ModsFile ($CopyFile, $CopyTo) {
Return Return
} }
function Edit-ModsFile ($ModsFile, $FindText, $ReplaceText) {
if (Test-Path "$ModsFile") {
((Get-Content -path $ModsFile -Raw) -replace "$FindText","$ReplaceText") | Set-Content -Path $ModsFile -Force -ErrorAction SilentlyContinue | Out-Null
}
Return
}
function Grant-ModsPath ($GrantPath) { function Grant-ModsPath ($GrantPath) {
foreach ($path in $GrantPath) foreach ($path in $GrantPath)
{ {