Mods Find/Replace text in file
parent
dd4cc700f2
commit
d000abf675
|
@ -44,6 +44,15 @@ $DelFile = @("")
|
|||
$CopyFile = ""
|
||||
$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"
|
||||
$GrantPath = @("")
|
||||
|
||||
|
@ -78,6 +87,9 @@ if ($DelFile) {
|
|||
if ($CopyFile -and $CopyTo) {
|
||||
Copy-ModsFile $CopyFile $CopyTo
|
||||
}
|
||||
if ($ModsFile -and $FindText -and $ReplaceText) {
|
||||
Edit-ModsFile $ModsFile $FindText $ReplaceText
|
||||
}
|
||||
if ($GrantPath) {
|
||||
Grant-ModsPath $GrantPath
|
||||
}
|
||||
|
|
|
@ -192,6 +192,13 @@ function Copy-ModsFile ($CopyFile, $CopyTo) {
|
|||
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) {
|
||||
foreach ($path in $GrantPath)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue