0

The function I write is suppose to create a new folder if there isn't one in the specific directory and if the folder is already in that directory then return True.

It seems some how my code on checking whether the fold exist in that directory is not working.

Help me please.

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Seeker
  • 1
  • try using `os.path.exists`to check if the path exist, if `False`, create a dir/file, if `True` the file exists. – m.i.cosacak May 19 '21 at 09:57

1 Answers1

0

Let's do a quick debug.

  • The current working directory is .../Desktop/Birth Of Evil/Project 2. Can we agree with that?

  • You're calling direct('Project 2/Files'), where a equals to Project 2/Files.

  • Inside direct, you get the current working directory, which is .../Desktop/Birth Of Evil/Project 2.

  • You check if the current working directory is equal to .../Desktop/Birth of Evil/%s.

  • Since a is equal to Project 2/Files, so you're checking if the current working directory is equal to .../Desktop/Birth of Evil/Project 2/Files.

  • Is the current working directory (.../Desktop/Birth Of Evil/Project 2) equal to .../Desktop/Birth of Evil/Project 2/Files? No, the latter is ending with a Files directory.

  • Enter the goddamn else. You're creating a new directory named .../Desktop/Birth of Evil/%s.

  • Since a is equal to Project 2/Files, so you're creating a new diretory in .../Desktop/Birth of Evil/Project 2/Files.

  • Whoa, it gives you the error! There is already an .../Desktop/Birth of Evil/Project 2/Files, so you can't create a new one in the same place.

You can just check if .../Desktop/Birth of Evil/%s exists. If it does exist, don't create a new directory in the same place, change the current working directory to there.

enzo
  • 9,861
  • 3
  • 15
  • 38