Firstly prjDir
must be a full path to prjDir
, i.e "\home\my_direc\", othwerise os.listdir
will try to find prjDir
in the current working directory of the script.
Secondly as os.listdir
returns only file/directory names not the full path, so to get the full path you can use os.path.join(prjDir,d)
.
import os
def mk_prjDir():
print "Checking to see if", prjDir, "exists.."
dirList = os.listdir(prjDir)
for d in dirList:
if os.path.isdir(os.path.join(prjDir,d)):
print (prjDir, "exists!")
else:
print (prjDir, "does not exist!")
mk_prjDir()
Update: I think I misunderstood your question if you only want to check whether a directory exists or not then try this:
def mk_prjDir():
print "Checking to see if", prjDir, "exists.."
if os.path.isdir(prjDir):
print (prjDir, "exists!")
else:
print (prjDir, "does not exist!")