133 of 151 menu

The path.isfile method of the os module

The path.isfile method checks whether the file specified in the method parameter exists. This method can also be used to determine whether the path specified in the parameter is a file. The method returns a boolean value: if the path is a file, then True, otherwise - False.

Syntax

import os print(os.path.isfile(path))

Example

Let's check again whether the given path is a file:

import os print(os.path.isfile('file.txt'))

The result of the executed code:

True

Example

Now let's check if the given path is a file:

import os print(os.path.isfile('dir'))

The result of the executed code:

False

See also

  • method path.isdir of module os,
    which checks the existence of a folder
  • method path.exists of module os,
    which checks the existence of a path
  • method copy2 of module shutil,
    which copies a file with metadata
  • method rename of module os,
    which renames a file and 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