C2W1 Cats vs Dogs: [Errno 17] File exists: '/tmp/tmpohn3lgwf'

I get the following error:

Details of failed tests for create_train_test_dirs

Failed test case: There was an error grading this function. Details shown in ‘got’ value below:.
Expected:
no exceptions,
but got:
[Errno 17] File exists: ‘/tmp/tmpohn3lgwf’.

Here is my code:

root_dir = ‘/tmp/cats-v-dogs’
if os.path.exists(root_dir):
shutil.rmtree(root_dir)

def create_train_test_dirs(root_path):
os.makedirs(root_path)
sd1=[“training”, “testing”]
sd2=[“dogs”,“cats”]
for i in sd1:
path=os.path.join(root_path,i)
os.makedirs(path)
for j in sd2:
os.makedirs(os.path.join(path,j))

try:
create_train_test_dirs(root_path=root_dir)
except FileExistsError:
print(“You should not be seeing this since the upper directory is removed beforehand”)

Everything works perfectly, but I don’t know how to eliminate the error. Please help

did your issue got resolved? I am getting the same error

Anyone have Information on this? I am getting a similar error.

Hi all, the problem here is that you are creating the root directory with os.makedirs(root_path) which the grader assumes already exists. This is a bug and we will fix it shortly. If you delete that line you will get full score.

But isn’t it necessary to create that directory? Why does the function assume it exists?
If I delete it, I get this error:
The system cannot find the path specified: ‘cats-v-dogs\training’

My comment was misleading, what I meant was that learners should avoid creating the top level directory directly (since os.makedirs creates all intermediate-level directories needed to contain the leaf directory). When I mentioned the function assumes it exists I meant within the grader not the assignment (since they run in different envs). Will edit my original comment.

This happens due to a bug in the grader which we will fix shortly. For now please avoid creating the top level directory directly and you should be fine.

I deleted that line and get this error:
[Errno 2] No such file or directory: '/tmp/

@Johnny_Dukovich would you mind sharing your function? It is hard trying to help if I don’t know the details of your implementation

Hi,
Is the issue resolved sir or you are still facing it?
Many thanks

Hi,
I still have this issue

I used
os.makedirs(os.path.join(root_path, “training”), exist_ok=True)
os.makedirs(os.path.join(root_path, “training/cats”), exist_ok=True)
os.makedirs(os.path.join(root_path, “training/dogs”), exist_ok=True)

os.makedirs(os.path.join(root_path, “validation”), exist_ok=True)
os.makedirs(os.path.join(root_path, “validation/cats”), exist_ok=True)
os.makedirs(os.path.join(root_path, “validation/dogs”), exist_ok=True)

and still have the same bug:
FileNotFoundError: [Errno 2] No such file or directory: ‘/tmp/PetImages/Cat//tmp/PetImages/Cat/9341.jpg’

this should help you