2
寻找这里: Is it possible to change an .rtf file to .txt file using some sort of batch script on Windows? 我有这样做的锯可以使用PowerShell。是一个完整的例子来做到这一点,但链接不起作用。 谁能告诉我,我可以解决它?谢谢。如何转换多个RTF文件为TXT文件
寻找这里: Is it possible to change an .rtf file to .txt file using some sort of batch script on Windows? 我有这样做的锯可以使用PowerShell。是一个完整的例子来做到这一点,但链接不起作用。 谁能告诉我,我可以解决它?谢谢。如何转换多个RTF文件为TXT文件
您可以使用.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)
运行PowerShell和在脚本的同一目录下查找,键入:翻译-RTF-TXT -src_file“pathfile \ rtf \ *。*”return me this: + CategoryInfo:ObjectNotFound:(translate-rtf-txt:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException 该脚本不能作为批处理工作? –
这是一个函数而不是完整的脚本。起床最简单的方式和运行是函数文件的全部内容复制到当前的PowerShell脚本,并从当前的脚本中调用该函数(翻译-RTF-TXT -src_file“C:\路径\为\ file.rtf” ) – Asnivor
现在,不要给我的错误,但输入例如:PS C:\用户\ ... \ RTF> \翻译-RTF-TXT -src_file“C:\用户\ ... \ RTF \# 730220210000-730220210000.rtf“不要使txt文件。哪里错了?毫无疑问,它也可以用多个文件使用mask * .rtf? –