-1

I am trying to find out if a folder exists but for some reason cannot. I am generating a string, and use os.path.isdir to find out if a folder with that string`s name already exists. The thing is - I get 'False' regardless.

import os

my_Folder_Name = 'some_string' #This is a string that I generate
print(os.path.isdir("\\" + my_Folder_Name)) #Even if this folder exists - I get False

What am I doing wrong here?

Yair
  • 859
  • 2
  • 12
  • 27

2 Answers2

2
import os

my_Folder_Name = 'some_string' #This is a string that I generate
print(os.path.isdir(my_Folder_Name))

remove "//". Why are you using "//"?

Ashish
  • 4,206
  • 16
  • 45
0

Either use the relative path or the absolute one. Don't append '\' to your folder path.

print(os.path.isdir(my_folder_name))

(Sorry to digress, but variable names follow snake case convention in python. So if you can change that too, other python programmers would be happier)

hspandher
  • 15,934
  • 2
  • 32
  • 45