Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
edited by

I want to execute the code that will delete the file if it is existing in that directory. I have executed the code:

if os.path.exists(filename):

    os.remove(filename)

1 Answer

0 votes
by (108k points)

You can refer to the below code in Python:

try:

    os.remove(filename)

except OSError:

    pass

Related questions

0 votes
1 answer
0 votes
4 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...