2016-11-18 40 views

回答

1

您可以使用.NET通過實施System.Windows.Forms.RichTextBox控制,裝載richtextfile進去,然後拉着文字版本出來做這在PowerShell中很容易。這是迄今爲止我發現的最簡單,最快捷的方法。

我這樣做的功能正是這一點是在這裏:https://github.com/Asnivor/PowerShell-Misc-Functions/blob/master/translate-rtf-to-txt.ps1

要多這一點主要講解:

$rtfFile = [System.Io.FileInfo]"path/to/some/rtf/file" 
$txtFile = "path/to/the/destination/txt/file" 

# Load *.rtf file into a hidden .NET RichTextBox 
$rtBox = New-Object System.Windows.Forms.RichTextBox 
$rtfText = [System.IO.File]::ReadAllText($rtfFile); 
$rtBox.Rtf = $rtfText 

# Get plain text version 
$plainText = $rtBox.Text; 

# Write the plain text out to the destination file 
[System.IO.File]::WriteAllText($txtFile, $plainText) 
+0

運行PowerShell和在腳本的同一目錄下查找,鍵入:翻譯-RTF-TXT -src_file「pathfile \ rtf \ *。*」return me this: + CategoryInfo:ObjectNotFound:(translate-rtf-txt:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException 該腳本不能作爲批處理工作? –

+0

這是一個函數而不是完整的腳本。起牀最簡單的方式和運行是函數文件的全部內容複製到當前的PowerShell腳本,並從當前的腳本中調用該函數(翻譯-RTF-TXT -src_file「C:\路徑\爲\ file.rtf」 ) – Asnivor

+0

現在,不要給我的錯誤,但輸入例如:PS C:\用戶\ ... \ RTF> \翻譯-RTF-TXT -src_file「C:\用戶\ ... \ RTF \# 730220210000-730220210000.rtf「不要使txt文件。哪裏錯了?毫無疑問,它也可以用多個文件使用mask * .rtf? –