PDA

View Full Version : [SLEEPER:] Extract values from multiple text files



swaggerbox
06-10-2009, 12:43 AM
I have multiple text files in C:\Test folder. Inside each text file are datasets that begins with <COVER> and ends with <ECOVER>. Both Cover and ECOVER tags have the same values.

I want to extract the values of all <COVER> and <EAC> in a LOG file that corresponds to the filename of the specific TXT file followed by LOG extension and count the number of datasets. For example, if C:\Test folder contains 2 TXT files, it should generate 2 LOG files. For this example, I used XXXX.TXT which contains three datasets with the following information:

<COVER> XXXXXXX-A
<MTM> 1
<WF> XXXXXX
<EAC> YYYY
<PP> 1
<ECOVER> XXXXXXX-A

<COVER> ZZZZZZZ-A
<MTM> 1
<WF> XXXXXX
<EAC> YYYY
<PP> 1
<ECOVER> ZZZZZZZ-A

<COVER> YYYYYYYY-A
<MTM> 1
<WF> XXXXXX
<EAC> YYYY
<PP> 1
<ECOVER> YYYYYYYY-A

This would generate XXXX.LET which has an output like the one shown below:

-----------------------------------------------------------------------
Please find the data of 3 files in this shipment.
Please find the data for the following files in XXXX.TXT

Cover ID. EAC ID.
========== ===========
XXXXXXX-A YYYY
ZZZZZZZ-A YYYY
YYYYYYYY-A YYYY
-----------------------------------------------------------------------

Is there a way I can do this using VBA?

fumei
06-10-2009, 09:00 AM
Yes.

I am a little confused though.

"it should generate 2 LOG files"

"This would generate XXXX.LET which has an output like the one shown below:"

So is that content the content of just ONE of the two LOG files you want to generate?

In any case, use the Dir function to go through the files in your folder, and a dedicated search function to get your results.

swaggerbox
06-10-2009, 04:18 PM
"C:\Test folder contains 2 TXT files, it should generate 2 LOG files" This means for every TXT file there is a corresponding LOG file containing the desired output. For this example, XXXX.TXT would generate XXXX.LET or XXXX.LOG.

Could you show me how can I extract the value of <COVER> and <EAC>? I am a newbie and need someone to show me the ropes.

Thanks