How Can I Modify External Files?

threeo2

Registered User.
Local time
Today, 12:25
Joined
Feb 11, 2003
Messages
31
I posted this question before but i'm rephrasing it now because i realized i was going about it the hard way.

I have a file on my c: drive outside of access that i need to modify. It is a Eudora mailbox file with an extension of .mbx but it is just a text file. I need to "scan" through it for junk text and delete that text (kind of like the find & replace function.) I was working on code to bring it into a table via line input, then delete the junk text and transfer text back to the .mbx file. Was getting close when I realized this is really the hard way to do it because I don't need the text to be brought into a table or access at all. The only reason I'm doing it from access is because that's where the main menu is that my users see is and it's a good place for a button.
Below is a sample of the text. This format repeats throughout the file as each time is a different email message in the mailbox folder. The junk text i want to delete always starts with "The following operations are" and ends before "</x-flowed>" but is usually not the same length or amount of lines in the file. So can anyone help with a way to do this without bringing it a table?
THNX!


-----------------SAMPLE TEXT IN FILE------------------
From ???@??? Mon Aug 25 16:05:54 2003
X-Sender:
X-Mailer: Date: Tue, 12 Aug 2003 12:36:19 -0400
To:
From:
Subject:

<x-flowed>

CASE FILE CONFIRMATION NOTICE

CASE# 1293745682221
UE ID# 0009777162131
DATE: 06/21/2003
REP: J. MYERS
STATUS: PENDING

The following operations are--------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------
JUNK TEXT-------------------------------------------------------------------------------------------

</x-flowed>
:):)
 
Maybe

It has been several years, but I did something similiar. I think I used a variation of the following. You might experiment with the code and see what you come up with. This code comes from the MS VBA help screen, OpenAsTextStream method:

The OpenAsTextStream method provides the same functionality as the OpenTextFile method of the FileSystemObject. In addition, the OpenAsTextStream method can be used to write to a file.

The following code illustrates the use of the OpenAsTextStream method:

Sub TextStreamTest
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile "test1.txt" 'Create a file
Set f = fs.GetFile("test1.txt")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.Write "Hello World"
ts.Close
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
s = ts.ReadLine
MsgBox s
ts.Close
End Sub
 
three,

This time?

Code:
Dim buffer As String

Open "C:\SomeFile.mbx" for Input As #1
Open "C:\SomeFile.new" for Output  as #1

Line Input #1, buffer
While Not EOF(1)
   While Not EOF(1) Or Instr(0, buffer, "The following operations are") = 0)
      Line Input #1, buffer
      Wend
   If Instr(1, buffer, "The following operations are") > 1 Then
      Line Input #1, buffer
      While Instr(0, buffer, "</x-flowed>")
         Print #2, buffer
         Line Input #1, buffer
         Wend
   End If
   Wend
MsgBox("Your new file is in C:\SomeFile.new")
Close #1
Close #2

Didn't try it, but its close.

Wayne
 
THANKS ONCE AGAIN WAYNE, had to tweak it a bit but it works great now!

threeo2.
 

Users who are viewing this thread

Back
Top Bottom