>> So, what if you would like to
programmatically delete a file.
In this section, we'll be discussing how you can do
that using the Remove Method from the OS module.
>> Let's look at an example of how we
can remove a file using Python.
And we're going to start here
by seeing what directory we're in.
And so, I've imported OS and I'm going
to get the current working directory,
and then I'm going to see if
this parent directory path exists in that directory.
So, let's go ahead and run that code.
And we see that we are in the home nbuser library.
And that yes, the parent directory is in that library,
that is true because we did the OS path
exist and checked for
the parent directory and it says yes, it is true.
So, now I'm going to create or overwrite
a file because I'm going to
open a file in write mode here.
And it's going to be in the parent directory and
it's going to be called this tmp file to be deleted.
We're going to go ahead and create that and close it.
And now, we're just going to look and
see if that file really was created.
So, here it is, the tmp file to be
deleted and it's the content in that parent directory.
So, after all that, how do we remove it?
Well, we simply, after importing OS,
we do.remove and the path to a file.
Now, this only removes files.
So, let's go ahead and try that and maybe that worked.
Let's look again at the directory,
and we see that tmp file is now gone from
the files that are in there whereas
previously it was right there.
>> So to recap, in this section,
we learned how you can use the Remove Method from
the OS module to delete
a file provided you have the file's path name.