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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unformatted Text File 1

Status
Not open for further replies.

Trudye

Programmer
Sep 4, 2001
932
US
Hey Guys;

My client receives a unformatted text file that must be opened in NotePad. It contains a 39 byte hdr (which must remain) a large amount of garbage which must be deleted. The end of the garbage and the beginning of the good data is denoted by the bytes "O1CR".

Are there any ideas how this can be accomplished. This is a very large file thus an array is not feasible.

Thanx
Trudye
 
In a macro, create a new blank file and move the 'important' contents from the unformatted text file (one line at a time0, delete the original file, rename the new file?

I am sorry I have not succeeded in answering all of your questions.
In fact, I apologize for not completely answering any of them.
The answers I have however do serve to raise a whole new set of questions I had not previously thought of. In some ways, I am as confused as you are but I believe my confusions are (as always) on a higher plane and
 
The 01cr characters do not appear at the beginning of the line, maybe and often is in the middle of the line.

Or am I failing to understand your reply?

OBTW, I failed to mention that it is an XML file. In the past (because no one know XML) the User has opened the file in Notepad and manually deleted the garbage data.

There has got to be a way to do this programmatically.

Thanks for replying,
Trudye
 
Use [tt]InStr()[/tt] to find '01cr', a sample routine would look something like this:
Code:
Sub ReWriteFile()
Const TempOut = "C:\output.xml"
Dim blnMove As Boolean
Dim lngInputFile As Long, lngOutputFile As Long
Dim strSourceFileName As String, strCurrentLine As String

'Initialize
blnMove = False
'Change this to match your environment
strSourceFileName = "[i]C:\SourceFile.xml[/i]"

'Open the input and output files
lngInputFile = FreeFile
Open strSourceFileName For Input As #lngInputFile
lngOutputFile = FreeFile
Open TempOut For Output As #lngOutputFile

'Get the first (header) line
Line Input #lngInputFile, strCurrentLine
Print #lngOutputFile, strCurrentLine

'Cycle through the rest of the file
Do
  Line Input #lngInputFile, strCurrentLine
  'Test for 01cr
  If [b]InStr([/b]strCurrentLine, "01cr"[b])[/b] > 0 Then
    blnMove = True
  End If
  'if 01cr was found already, move the line
  If blnMove Then
    Print #lngOutputFile, strCurrentLine
  End If
Loop Until EOF(lngInputFile)

'Close the files
Close #lngInputFile
Close #lngOutputFile

'Move the file (kill-copy-kill trick avoids using FSO)
Kill strSourceFileName
FileCopy TempOut, strSourceFileName
Kill TempOut
End Sub

I am sorry I have not succeeded in answering all of your questions.
In fact, I apologize for not completely answering any of them.
The answers I have however do serve to raise a whole new set of questions I had not previously thought of. In some ways, I am as confused as you are but I believe my confusions are (as always) on a higher plane and
 
Thanks much CautionMP I'll try it and let you know

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top