Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-format an RTF file into an ASCII Text file

Status
Not open for further replies.
May 11, 2005
6
I have multiple RTF files (In numerical sequence. Ex: 1.rtf, 2.rtf, etc.). Does anyone know how I can make a program that will format all the RTF files in this directory into ASCII Text files?

I appreciate your help,

Jarrett
 
Finding all the RTF files is as simple as using ADIR():

nFileCount = ADIR(aRTFFiles, "*.RTF")

I'm not sure how you change RTF to plain text, though.

Tamar
 
The RTF holds the text of the document as plain ASCII and making plain text into RTF is just <g> a process of adding tags like \par and {\f0\froman Times New;}.

An RTF file from WordPad has a fairly simple structure and it should be easy to go through it looking for these sequences and removing them. An RTF from Word is a mess.

The easiest way would be to write a macro in Word.

Is this a one-off job or do you have to automate it?

Geoff Franklin
 
I have to automate it. Basically I have over 1000 rtf files (in numerical sequence). I need to create a program that can take all the rtf files and convert them into ASCII text files
 
I'd suggest you experiment with a Word macro. This is as rough as old boots - it's slow but it does the job
Code:
Sub Macro1()

Dim strFile
Dim strRoot
Dim lngLen

 strFile = Dir("g:\*.rtf")
 Do While Len(strFile) > 0
   lngLen = Len(strFile)
   strRoot = Left(strFile, lngLen - 4)
   '-- Now we can open the rtf and SaveAs text
   Documents.Open FileName:="g:\" & strFile
   ActiveDocument.SaveAs FileName:="g:\" & strRoot & ".txt", FileFormat:=wdFormatText
   ActiveDocument.Close
   '-- Get the next RTF
   strFile = Dir()
 Loop
End Sub

Geoff Franklin
 
Do you know of a program I can use that runs in dos foxpro or even Visual Foxpro?

Thanks,

Jarrett Chanzes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top