Background: I changed filenames of .mp4 videos to lowercase and replaced the special characters as well as spaces. Now I have to change the associated URLs inside of .txt files in a similar manner. There are many text files which contains plenty of these URLs referring to the videos.
Issue: I should replace the special characters in every string between "flashplayer" and "/flashplayer" at any textfile, but must not change anything outside the flashplayer tags.
I don't know how to select the strings between "flashplayer" and "/flashplayer" for the replacement.
Sample string:
(flashplayer width="640" height="480" position="1")file=/wiki/data/media/sales/a/ö 2.mp4&config=/wiki/lib/plugins/flashplayer/config_video.xml&start=0(/flashplayer)
This sample is included in a textfile (DokuWiki page). The () imply tag characters.
Sample output string:
(flashplayer width="640" height="480" position="1")file=/wiki/data/media/sales/a/oe_2.mp4&config=/wiki/lib/plugins/flashplayer/config_video.xml&start=0(/flashplayer)
The replacement with rename-item should be:
- ä = ae
- ö = oe
- ü = ue
- ' ' = '_'
Update: the script looks like:
# vars (User-Eingabe)
$source = "d:\here\name\test\pages"
$search = '(\<flashplayer.*?\>file\=/wiki/87sj38d/media)(.*?)(\<\/flashplayer\>)'
$a = 1
Write-Host "`nSource:`t $source`n"
# replace special characters
gci $source -r -Filter *.txt | ForEach-Object {
$text = Get-Content $_.FullName | ForEach-Object {
if($_ -match $search) {
$_ -replace [Regex]::Escape($Matches[2]), ($Matches[2] -replace'ö', 'oe' -replace'ä', 'ae' -replace'ü', 'ue' -replace'\s', '_' )
$output = $Matches[2]
$tags = $a++
Write-Host "`nTag $tags : $output"
} else {
$_
}
}
$text | Set-Content $_.FullName
}
The textfiles contain a line of code like this:
{{backlinks>path:product:description:kennwort_aendern}}
The script works only if I delete this line of code. Otherwise the string between the flashplayertags stay the same. Confusingly enough, the replacement operates sometimes and sometimes not. The string between the flashplayertags can contain many special characters. See sample string:
<flashplayer_width="640"_height="480"_position="1">file=/wiki/87sj38d/media/ab/any/test/1001_Grundlagen Kennwort ändern.mp4&image=/wiki/87sj38d/media/ab/any/test/1001_Grundlagen Kennwort ändern.jpg&config=/wiki/lib/plugins/flashplayer/config_video.xml&start=0</flashplayer>
The Write-Host $output shows all strings correctly but the replacement doesn't function properly.