Here on my programming environment, I have these files directory, which has these three files.
Each of them has this unwanted comma of the end, and I want to remove that comma from every file via
Python formats that I'm going to iterate over these files and to iterate over these files.
First, we need a list of these file paths to create a list.
It's good to use from past leap import path solver path class.
And as you may know from the previous videos with file operations first, when we import path, we want
to create a file directory or something like that.
So which is equal to path files?
Files is the name of the folder so that we create, as you can see, files easier as.
A path object type that points to the fires folder, and we can make use of that by iterating for file
path and file their dots ITR dear.
And you'll see that file path as each of the paths or these files.
So we have access to the file paths, then we can go ahead and open all these files.
Births so far path in open as an read mode as a file.
So file is the file object.
Don't confuse file with file path.
File path is the path to that file object in that file object.
We apply file that is read and stored that stream in a contents variable.
Then we modify that content.
So we saw in a new variable the texts accept the lost character.
So with that slice, you know, from the previous video that said, we extract all the characters,
but the lost one.
Then what we do with this new string is we open a new file path.
So if you want to override the existing files, you want to do that.
So you want to use the same file path, which means you will override the existing files with the new
files that you open in rides modes here as file again file.
That's roids new content, but I would like to make a copy of this folder to back it up.
Now in Europe, I don't have an option to make a copy of this folder if you were locally in your computer.
You can just copy that folder and paste it in another name.
If you are on Ripple, you want to go to the shell and first make a new directory where to put the new
files or add Kadir files back up.
That gives you a new empty directory.
Then you want to copy S..
That's a to preserve file attributes and then files Slashdot and files back up.
There's a complete command set around that.
And now you should see all the original files inside the Files backup folder, so let's carry on with
the codes.
Now I can run these codes without losing the original files.
So run and let's check file for common file five.
No comma file six no comma of the ends.
So that is the complete code.
In the next video, we will replace a word with another word from all the files.
I'll talk to you in the next video.