Remove a file

EasyOS Module Programs · 20 of 49

Write a Python program to remove a file at a given path.

Advertisement
Output
False

Approach

  1. os.remove(); check that it exists first.

Solution

Python
import os open("old.log", "w").close()if os.path.exists("old.log"):    os.remove("old.log")print(os.path.exists("old.log"))
Output
False

Learn the concept

New to this topic? Read the lesson, then come back.

More os module programs

← All 49 OS Module Programs

Leave a Comment