在PowerShell中将.rtf文件转换为.doc,然后将.doc重新转换为.rtf(WMF注册表修复程序)-文件大小优化 [英] Converting .rtf files to .doc and then .doc back to .rtf in PowerShell (WMF registry fix) - file size optimization

查看:184
本文介绍了在PowerShell中将.rtf文件转换为.doc,然后将.doc重新转换为.rtf(WMF注册表修复程序)-文件大小优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Powershell中创建一个脚本,该脚本会将我的所有文件从.rtf转换为.doc,然后再转换.我想这样做是因为我已经应用了注册表修复程序,该修复程序将在此类转换后减小我的rtf文件的大小(它不会保存第二个WMF图像专用信息

I need to create a script in powershell with which will convert all my files from .rtf to .doc and then back. I want to do it because I have applied registry fix which will decrease size of my rtf files after such conversion ( It will not save second WMF image specyfic info http://support.microsoft.com/kb/224663 ).I imagine my script workflow as RTF_1 save to doc then close rtf1 delete rtf 1 , save doc to rtf2 , close doc , delete doc.

推荐答案

这是最终的工作脚本(无需删除,我决定不需要它)

Here is the final working script ( without deleting , I decided I do not need it )

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();

这篇关于在PowerShell中将.rtf文件转换为.doc,然后将.doc重新转换为.rtf(WMF注册表修复程序)-文件大小优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆