I would like to delete a directory that contains several files inside. It has the following structure:
carpeta
fichero1.txt
fichero2.txt
I tried to delete it directly with os.removedirs('carpeta')
but it gives me the error Directory not empty: 'carpeta'
. Also try to delete the files first and then the directory in the following way:
import os
os.remove('carpeta/fichero1.txt')
os.remove('carpeta/fichero2.txt')
os.removedirs('carpeta')
This, although it deletes the files to me, when it is going to delete the folder it continues giving me the same error; and even if it works it is not recommended because I do not know how many files I will have in that folder.