How to check whether a directory exists in Python

2 Answers

0 votes
from pathlib import Path

directory = "d:/directx/3d"

d = Path(directory)

if d.is_dir():
    print("directory exist")
else:
    print("directory not exist")


'''
run:

directory exist

'''

 



answered Oct 22, 2017 by avibootz
0 votes
import os.path

directory = "d:/directx/3d"

if os.path.exists(directory):
    print("directory exist")
else:
    print("directory not exist")


'''
run:

directory exist

'''

 



answered Oct 22, 2017 by avibootz

Related questions

1 answer 164 views
1 answer 151 views
3 answers 257 views
1 answer 171 views
1 answer 185 views
185 views asked Jul 12, 2020 by avibootz
1 answer 222 views
1 answer 196 views
...