people. I have in Folder1 a html file named file1.html that has this content:
Folder1 (file1.html)
<!-- FLAGS_1 -->
<div class="cautareField">
<div align="right">
<a href="https://neculaifantanaru.com/izolarea-cercetatorului-in-cursa-lunga-a-leadershipului.html"> <a href="https://neculaifantanaru.com/fr/l-isolement-du-chercheur-dans-le-marathon-de-leadership.html"> <a href="https://neculaifantanaru.com/en/the-flashing-of-a-mind-inclined-towards-the-infinite.html">
</div>
</div>
<!-- FLAGS -->
Folder2 (filexxx.html)
<!-- FLAGS_1 -->
<div class="cautareField">
<div align="right">
<a href="https://neculaifantanaru.com/index.html"> <a href="https://neculaifantanaru.com/fr/index.html"> <a href="https://neculaifantanaru.com/en/index.html">
</div>
</div>
<!-- FLAGS -->
And I want to move this content from <!-- FLAGS_1 --> to <!-- FLAGS --> in the same place on other several html files located in Folder2, that has different names. The only problem is that my code fails to make the copy, it only moves file1.html to Folder2 that has different names, but the same structure (only the links are different). Don't know why.
$sourceFiles = Get-ChildItem -Path "c:\Folder1" -Filter "*.html";
$destinationFolder = 'c:\Folder2'
foreach ($file in $sourceFiles) {
$sourceContent = Get-Content $file.FullName -Raw
$contentToInsert = [regex]::match($sourceContent,"(?ms)<!-- FLAGS_1 -->(.+)<!-- FLAGS -->").value
$destinationContent = Get-Content $destinationFolder\$($file.Name) -Raw
$destinationContent = $destinationContent -replace '(?ms)<!-- FLAGS_1 -->(.+)<!-- FLAGS -->',$contentToInsert
Set-Content -Path $destinationFolder\$($file.Name) -Value $destinationContent -Encoding UTF8
} #end foreach file