Previously, we wrote a script to which concatenated all these files, and we ended up with this merger
that see us before, but we have these headers repeating in every X number of rows, so we want to do
this again.
But without the headers, without this and without that, just this one.
So we import path, we create a path object for the directory, which contains the files we iterate
over those files.
We open each file, we read the content and then we add that contents to an empty string, so we keep
adding to that string.
But this time, we don't want to add the first line.
In that case, we want to treat the content on a line by line basis.
So currently, we have the content stored in this content variable as a string one single string that
happens when you use the leads methods.
But if you use the read lines, what we get is a list.
Let's try that to you with open files, for example.
File for that See as V in read mode as file.
Content illegal to file that reads lines.
Let's see what content is this time.
So it's a list of strings.
Each string represents one line.
So is the first line and the break line as well.
Backslash and the second line with a break line and so on.
So now that we have this content list, we want to filter that out.
So let's say new content is equal to content and we get all the items of the list.
But the first one?
So in other words, we get from the item with index one.
This has an index of one.
This is an index of two, three and so on.
So we don't get the item with index zero, which is the first line.
Of course, this will do this filtering for all of the files, but we need the header for the first
file rights.
So we want to do some sort of, if conditional here, rights somewhere in here.
So we could say something like if index equal to zero.
I'll tell you what index is in just a bit then, so if we're dealing with the first file, which will
have an index of zero in the loop, then we want to do merged or yeah, we want to do this here.
Merge a single to merge plus content.
Ale's merge, a single to merge, plus new content.
Plus that's backslash.
Now, what is index index now could be for index five path in enumerate?
That so that's a sane list, and I'll show you what this does.
Let's suppose we have the list of file paths for the paths and which looks something like file for the
C as V file five, the C as V and so on.
Let's keep it with two only now when you do four index file path in enumerate file paths.
Index will be the index of each of these.
Items.
So this is a way to extract the index, and therefore we see if index is equal to zero, then we don't.
Remove the heads or so we use the contents as it is, otherwise we use the new contents, which does
not have the header.
Right.
And then finally, we write the merged file in this file, so merge the CSB and we should be ready to
run this.
So run.
Yes, we do get this error because it's trying to concatenate string with a list.
So contents here is a list and merge these a string.
So we want to convert that contents into a string because you saw that content was something like I-D
and units and so on.
We want to concatenate that's using the join method, which works like this.
If you have, for example, a small string such as adults and you say, join this Join methods.
If you give it a list as inputs and you have some lines such as B, C, some items D E F and you execute
this, the join method will make a string out of those items and it will join them with these dots.
So if you had other items, the dots goes between the items.
Always.
As you can see here, no evidence is an empty string.
What you get is this.
So nothing is applied between the items, but still you get one single string.
So now let's convert.
Where do we do the conversion before we do that, before we append content to merged?
So just before the first conditional a string join content.
So that is equal to content.
You can override the existing variable, so right, the screen there currently, we have the least now
where the string content is equal to that.
The same we do for the else, Port New Contents, a sequel to that, but join.
New content, then we have pens, new content to emerge, so run that.
Go to merchants and sweet gets what we were asking for.
So the heads are in the first line, then we have the first line with dots, our second thoughts and
then comes the delta of the second file and then comes the delta of the third file.
So that is the final code.
Thank you for falling, and I'll talk to you later.
Sue.