Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

In the os module in Python, is there a way to find if a directory exists, something like:

os.direxists(os.path.join(os.getcwd()), 'new_folder'))

# in pseudocode True/False

1 Answer

0 votes
by (106k points)

To check the existence of a directory in Python you can use the methods of os module which are os.path.isdir, or os.path.exists:- //What are these?? Path? Directories? What exactly?


This function returns True if the mentioned path is an existing directory. 


This function returns True if path refers to an existing path or an open file descriptor. It returns False for broken symbolic links. The os.path.exist() function may return false on some platforms if permission is not granted to execute os.stat()on the requested file, even if the path physically exists.


The method os.stat() gets the status of a file or a file descriptor and it performs the equivalent task that the stat() system call does on the given path. 

import os print(os.path.isdir("/file’s address/")) print(os.path.exists("/parent address of file/file name"))

Related questions

0 votes
1 answer
+3 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Sep 16, 2019 in Python by Sammy (47.6k points)
+1 vote
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories