os.path.exists will also return True if there's a regular file with that name.

os.path.isdir will only return True if that path exists and is a directory, or a symbolic link to a directory.

Answer from Pavel Anossov on Stack Overflow
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ os.path.html
os.path โ€” Common pathname manipulations
Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-os-path-isdir-method
os.path.isdir() method | Python - GeeksforGeeks
1 week ago - Explanation: os.path.isdir(path) checks if path refers to an existing directory.
Discussions

python - pros and cons between os.path.exists vs os.path.isdir - Stack Overflow
However this can cause issues with os.rmdir because it will fail on a symlink even if it is a symlink to a directory. 2019-06-04T21:49:54.647Z+00:00 ... Just like it sounds like: if the path exists, but is a file and not a directory, isdir will return False. More on stackoverflow.com
๐ŸŒ stackoverflow.com
os.path.isdir is always returning false
So I user the following code: #!/usr/bin/env python import os if os.path.isdir("/home/testaccaunt/public_html"): print "I am a directory" else: print "I am NO directory" So that is just a first test for me and the result is always that my public_html folder is no directory. More on community.unix.com
๐ŸŒ community.unix.com
8
0
May 21, 2009
What is fast way to check 'isDir' in python? - Stack Overflow
I know os.path.isdir is problem. More on stackoverflow.com
๐ŸŒ stackoverflow.com
`os.path.isdir()` devuelve falso
Subreddit for posting questions and asking for general advice about all topics related to learning python. More on reddit.com
๐ŸŒ r/learnpython
12
1
April 22, 2022
๐ŸŒ
Reddit
reddit.com โ€บ r/pythonlearning โ€บ os.isdir vs path.isdir
r/PythonLearning on Reddit: os.isdir vs Path.isdir
April 2, 2025 -

Im creating a script to convert multiple image files in folder A and saving to folder B. But if folder B doesn't exist then i need to creat a folder. In searching for solutions i came across two ways to check if a folder exists, being from os library os.path.isdir and from pathlib Path.isdir. Whats the difference. They both seem to do the same thing.

Which bring me to another question, is the .isdir the same method being applied to two different functions in two different libraries? How do we the determine which library would be best for whatever problem is being solved.

๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ os_path_isdir.htm
Python os.path.isdir() Method
The Python os.path.isdir() method is used to check whether a given path exists and points to a directory in the file system. The method returns "True" if the specified path exists and refers to a directory in the file system, and "False" otherwise.
Find elsewhere
๐ŸŒ
TradingCode
tradingcode.net โ€บ python โ€บ os-path-isdir-function
Check if path is a directory with Python's `os.path.isdir()` function
With the os.path.isdir() function Python sees if a relative or absolute path is an existing directory. This code tutorial explains with several examples.
๐ŸŒ
Unix Community
community.unix.com โ€บ shell programming and scripting
os.path.isdir is always returning false - Shell Programming and Scripting - Unix Linux Community
May 21, 2009 - So I user the following code: #!/usr/bin/env python import os if os.path.isdir("/home/testaccaunt/public_html"): print "I am a directory" else: print "I am NO directory" So that is just a first test for me and the result is always that my public_html folder is no directory.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ pathlib.html
pathlib โ€” Object-oriented filesystem paths
February 23, 2026 - Changed in version 3.14: The methods given above now return False instead of raising any OSError exception from the operating system. In previous versions, some kinds of OSError exception are raised, and others suppressed. The new behaviour is consistent with os.path.exists(), os.path.isdir(), etc.
๐ŸŒ
Astral
docs.astral.sh โ€บ ruff โ€บ rules โ€บ os-path-isdir
os-path-isdir (PTH112) | Ruff
import os os.path.isdir("docs") Use instead: from pathlib import Path Path("docs").is_dir() While using pathlib can improve the readability and type safety of your code, it can be less performant than the lower-level alternatives that work directly with strings, especially on older versions of Python.
๐ŸŒ
Google Translate
translate.google.com โ€บ translate
os.path โ€” Common pathname manipulations โ€” Python 3.14.4 documentation
This follows symbolic links, so both islink() and isdir() can be true for the same path. Changed in version 3.6: Accepts a path-like object. ... Return True if path refers to an existing directory entry that is a junction. Always return False if junctions are not supported on the current platform. Added in version 3.12. ... Return True if path refers to an existing directory entry that is a symbolic link. Always False if symbolic links are not supported by the Python runtime.
Top answer
1 of 2
2

os.path.isdir seems to be the fastest implementation:

from pathlib import Path
import os
import win32api
import glob
import timeit


def os_isDir(files):
    return [os.path.isdir(fullPath) for fullPath in files]

def os_NOT_isFile(files):
    return [not os.path.isfile(fullPath) for fullPath in files]

def pathlib_isDir(files):
    return [Path(fullPath).is_dir() for fullPath in files]

def winapi_GetFileAttributesA(files):
    return [win32api.GetFileAttributes(fullPath) == 16 for fullPath in files]


files = glob.glob('C:\\Windows\\System32\\*')
for func in ("os_isDir", "os_NOT_isFile", "pathlib_isDir", "winapi_GetFileAttributesA"):
    t1 = timeit.Timer(f"{func}({files})", f"from __main__ import {func}")
    print(f"Evaluation {len(files)} paths using {func} took: {t1.timeit(number=5)} seconds\n")

Out (on a Win7 VM):

Evaluation 3294 paths using os_isDir took: 2.1250754 seconds

Evaluation 3294 paths using os_NOT_isFile took: 2.7074766999999995 seconds

Evaluation 3294 paths using pathlib_isDir took: 3.4624453000000006 seconds

Evaluation 3294 paths using winapi_GetFileAttributesA took: 2.2789655999999994 seconds
2 of 2
1

Perhaps the fastest way to check if something is a directory is to not have to check at all. If you wish to iterate all files in a directory tree (you haven't actually specified whether this is the case), you should consider using os.walk:

os.walk(top, topdown=True, onerror=None, followlinks=False)

Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).

The 3rd element of the tuple (filenames) is guaranteed to not be a directory. This is how you would print all file names in a directory tree:

import os

def walk_directory(directory_name):
    for dirpath, dirnames, filenames in os.walk(directory_name):
        for filename in filenames:
            fullpathname = os.path.join(dirpath, filename)
            print(fullpathname)

Otherwise, you should be using an isDir method call. For example, if you just wanted to iterate all the files in a single directory, then one way is as follows:

from pathlib import Path

def list_directory(directory_name):
    # non-recursive
    for p in Path(directory_name).glob('*'):
        if not p.is_dir():
            #filename = str(p) # to convert Path to a string
            print(p)
๐ŸŒ
Reddit
reddit.com โ€บ r โ€บ learnpython โ€บ comments โ€บ u9hi3o โ€บ ospathisdir_returns_false
`os.path.isdir()` devuelve falso : r/learnpython
April 22, 2022 - Subreddit for posting questions and asking for general advice about all topics related to learning python. Members ยท Online โ€ข ยท grossartig_dude ยท Estoy intentando comprobar si existe una carpeta usando: path = r"Este PC\Notas de Bassel\Almacenamiento interno\Audiolibros" print(os.path.isdir(path)) Siempre devuelve falso aunque la carpeta existe (es la carpeta de mi telรฉfono que estรก conectado al portรกtil).
๐ŸŒ
Google Translate
translate.google.com โ€บ translate
How to test if a path is a directory with Python?
Often when Python iterates through a directory, we work with both files and folders in that directory. But sometimes we only need to work with those directory paths that are folders. To do this, we filter the directory entries with the os.path.isdir() function.
๐ŸŒ
Google Translate
translate.google.com โ€บ translate
pathlib โ€” Object-oriented filesystem paths โ€” Python 3.14.3 documentation
Changed in version 3.14: The methods given above now return False instead of raising any OSError exception from the operating system. In previous versions, some kinds of OSError exception are raised, and others suppressed. The new behaviour is consistent with os.path.exists(), os.path.isdir(), etc.
๐ŸŒ
Desy
hasyweb.desy.de โ€บ services โ€บ computing โ€บ python โ€บ node182.html
os.path.isdir()
Returns True, if the argument points to an existing directory ยท In [2]: import os In [3]: os.path.isdir('/etc') Out[3]: True