Skip to content

Instantly share code, notes, and snippets.

@stahler
Created March 3, 2019 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stahler/78a27565ffaa9573a8b07beffc9b34e2 to your computer and use it in GitHub Desktop.
Save stahler/78a27565ffaa9573a8b07beffc9b34e2 to your computer and use it in GitHub Desktop.
# create some test files
1..9 | foreach -Begin {
Set-Location C:\TEMP
} -Process {
$str = "<html>NewFile$PSItem</html>"
Add-Content -Value $str -Path "./OldFile$PSItem.html"
}
# change the name of the test files
$files = Get-ChildItem O*.html
foreach ($file in $files) {
$text = Get-Content -Path $file.name
if ($text -match "<html>(?<name>.*)<\/html>") {
$newFile = $Matches.name
Rename-Item -Path $file.Name -NewName "$newFile.html"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment