118 of 151 menu

The remove method of os the module

The remove method deletes a file. In the method parameter, we specify the path to the file to be deleted. The method returns the value None. If the file to be deleted does not exist, then the FileNotFoundError exception is returned.

Syntax

import os os.remove(path to file)

Example

Let's delete the file 'file.txt':

import os os.remove('file.txt')

See also

  • method makedirs of module os,
    which creates folders
  • method mkdir of module os,
    which creates one folder
  • method rmdir of module os,
    which moves or deletes an empty folder
  • method rename of module os,
    which renames a file and folder
  • method path.isfile of module os,
    which checks the existence of a file
  • method copy2 of module shutil,
    which copies a file with metadata
  • method getcwd module os,
    which returns the current working directory
  • method listdir of module os,
    which returns a list of files in the working directory
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