E
E
Evgeniy_Lugovoi2021-06-26 16:58:50
Python
Evgeniy_Lugovoi, 2021-06-26 16:58:50

How can I delete a folder if it exists?

Good afternoon! I need to make it so that if there is an "images" folder in the folder, then either "images1" is created or it is deleted along with everything in it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2021-06-26
@Evgeniy_Lugovoi

Check if such a directory exists.
If there is, delete it recursively.
If you want to make it simpler, just write the code to remove the directory by wrapping it with a try-except.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question