Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,700 questions

57,013 answers

573 users

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 243 views
1 answer 247 views
3 answers 398 views
1 answer 251 views
1 answer 269 views
269 views asked Jul 12, 2020 by avibootz
1 answer 310 views
1 answer 309 views
...