132 of 151 menu

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.isfile of module os,
    which checks the existence of a file
  • method path.exists of module os,
    which checks the existence of a path
  • method mkdir of module os,
    which creates one folder
  • method path.join of module os,
    which unites the paths
  • method path.getsize of module os,
    which returns the size of the path in bytes
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline