【发布时间】:2020-01-13 23:22:42
【问题描述】:
我在here 上发现了类似的东西,但是当我尝试运行它时,我得到了错误。 因此我想知道是否可以制作一个可以获取 .RTF 文档并将它们全部转换为 .docx 文档的 Powershell 脚本?
【问题讨论】:
标签: powershell
我在here 上发现了类似的东西,但是当我尝试运行它时,我得到了错误。 因此我想知道是否可以制作一个可以获取 .RTF 文档并将它们全部转换为 .docx 文档的 Powershell 脚本?
【问题讨论】:
标签: powershell
使用它来将 rtf 转换为 docx:
Function Convert-Dir($path){
$Files=Get-ChildItem "$($path)\*.docx" -Recurse
$Word=New-Object –ComObject WORD.APPLICATION
foreach ($File in $Files) {
# open a Word document, filename from the directory
$Doc=$Word.Documents.Open($File.fullname)
# Swap out DOCX with PDF in the Filename
$Name=($Doc.Fullname).replace("docx","doc")
if (Test-Path $Name){
} else {
# Save this File as a PDF in Word 2010/2013
Write-Host $Name
$Doc.saveas([ref] $Name, [ref] 0)
$Doc.close()
}
}
$Files=Get-ChildItem "$($path)\*.rtf" -Recurse
$Word=New-Object –ComObject WORD.APPLICATION
foreach ($File in $Files) {
# open a Word document, filename from the directory
$Doc=$Word.Documents.Open($File.fullname)
# Swap out DOCX with PDF in the Filename
$Name=($Doc.Fullname).replace("rtf","doc")
if (Test-Path $Name){
} else {
# Save this File as a PDF in Word 2010/2013
Write-Host $Name
$Doc.saveas([ref] $Name, [ref] 0)
$Doc.close()
}
}
}
Convert-Dir "RtfFilePath";
代码来自和归属:https://gist.github.com/rensatsu/0a66a65c3a508ecfd491#file-rtfdocxtodoc-ps1
【讨论】: