The path.isdir method of the os module
The path.isdir method checks whether the folder specified in the method parameter exists. This method can also be used to determine whether the path specified in the parameter is a folder. The method returns a boolean value: if the path is a folder, then True, otherwise - False.
Syntax
import os
print(os.path.isdir(path))
Example
Let's check if the given path is a folder:
import os
print(os.path.isdir('dir'))
The result of the executed code:
True
Example
Now let's check again whether the given path is a folder:
import os
print(os.path.isdir('file.txt'))
The result of the executed code:
False
See also
-
method
path.isfileof moduleos,
which checks the existence of a file -
method
path.existsof moduleos,
which checks the existence of a path -
method
mkdirof moduleos,
which creates one folder -
method
path.joinof moduleos,
which unites the paths -
method
path.getsizeof moduleos,
which returns the size of the path in bytes