I have the code below. What does this code do. It make a PARSING. I replace a little bit a powershell code that can be found HERE
So, I must copy the content from <meta name="keywords" content="MY TEXT HERE"/>
and paste it into the content of <title>MY TITLE</title>
.
After running Powershell, I will get <title>MY TEXT HERE</title>
.
$sourcedir = "C:\Folder1\"
$resultsdir = "C:\Folder2\"
Get-ChildItem -Path $sourcedir -Filter *.html | ForEach-Object {
$content = Get-Content -Path $_.FullName -Raw
$replaceValue = ((Select-String -Pattern "(<title>).+(</title>)" -InputObject $content).Matches.Value).Split(" ")[1]
$findReplacement = Select-String -Pattern "(<meta name="keywords" content=").+("/>)" -InputObject $content
$split = ($findReplacement.Matches.Value).Split(" ")
$i = 0
do {
$find"/> = $split[$i]
$i++
} until ($find"/> -eq ""/>")
$replacementValue = ($split[1..($i - 2)]) -join ' '
$content.Replace("$replaceValue", "$replacementValue") | Out-File -FilePath $resultsdir\$($_.name)
}
The errors are on the lines that contains quotation marks/Double Quotes on the REGEX formulas, as below
"(<title>).+(</title>)" - This will select all words from the TITLE tag
"(<meta name="keywords" content=").+("/>)" - This will select all the words from the KEYWORDS tag
} until ($find"/> -eq ""/>") - This "/> represents the closing tag from the KEYWORDS tag
So, I must replace somehow those quotation marks/Double Quotes as to work well. Can anyone help me with an updated code?