這裏是最後的工作腳本(不刪除,我決定,我並不需要它)
param([string]$rtfpath,[string]$docpath = $rtfpath,[string]$docpath2 = $rtfpath2)
$srcfiles = Get-ChildItem $rtfPath -filter "*.rtf"
$docfiles = Get-ChildItem $docPath -filter "*.doc"
$saveFormat =[Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument");
$saveFormat_back =[Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
$word = new-object -comobject word.application
$word.Visible = $False
function saveas-DOC
{
$name = $rtf.basename
$savepath ="$docpath\rtf" + $name + ".doc"
write-host $name
Write-Host $savepath
$opendoc = $word.documents.open($rtf.FullName);
$opendoc.saveas([ref]$savepath, [ref]$saveFormat);
$opendoc.close();
}
function saveas-back_to_rtf
{
$name = $doc.basename
$savepath2 ="$rtfpath2\doc" + $name + ".rtf"
write-host $name
Write-Host $savepath
$opendoc = $word.documents.open($doc.FullName);
$opendoc.saveas([ref]$savepath2, [ref]$saveFormat_back);
$opendoc.close();
}
ForEach ($rtf in $srcfiles)
{
Write-Host "Processing :" $rtf.FullName
saveas-DOC
}
ForEach ($doc in $docfiles)
{
Write-Host "Processing doc file :" $doc.FullName
saveas-back_to_rtf
$doc = $null
}
$word.quit();