Created
February 27, 2026 16:26
-
-
Save eugrus/68840fdbcdc546aa1bd3a91e3d5365fb to your computer and use it in GitHub Desktop.
Convert all RTFs from a folder to DOCX using MS Word
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $folder = "." | |
| $word = New-Object -ComObject Word.Application | |
| $word.Visible = $false | |
| # 6 = wdFormatXMLDocument (DOCX) | |
| $saveFormat = 12 | |
| Get-ChildItem -Path $folder -Filter *.rtf | ForEach-Object { | |
| $rtfPath = $_.FullName | |
| $docxPath = [System.IO.Path]::ChangeExtension($rtfPath, ".docx") | |
| $doc = $word.Documents.Open($rtfPath, $false, $true) | |
| $doc.SaveAs([ref]$docxPath, [ref]$saveFormat) | |
| $doc.Close() | |
| } | |
| $word.Quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment