Avoid exceptions in Write-ReplaceContentInFile
This commit is contained in:
parent
bc30cc911a
commit
5e3384b4fd
1 changed files with 9 additions and 4 deletions
|
@ -20,12 +20,17 @@ namespace LANCommander.PowerShell.Cmdlets
|
|||
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
var contents = File.ReadAllText(FilePath);
|
||||
var regex = new Regex(Pattern, RegexOptions.Multiline);
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
var contents = File.ReadAllText(FilePath);
|
||||
var regex = new Regex(Pattern, RegexOptions.Multiline);
|
||||
|
||||
var result = regex.Replace(contents, Substitution);
|
||||
contents = regex.Replace(contents, Substitution);
|
||||
|
||||
WriteObject(result);
|
||||
File.WriteAllText(FilePath, contents);
|
||||
|
||||
WriteObject(contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue