Deleting files which start with a name Python

python

Solution

import os, glob
for filename in glob.glob("mypath/version*"):
    os.remove(filename) 

Substitute the correct path (or `.` (= current directory)) for `mypath`. And make sure you don't get the path wrong :)

This will raise an Exception if a file is currently in use.

Problem

I have a few files I want to delete, they have the same name at the start but have different version numbers. Does anyone know how to delete files using the start of their name? ``` Eg. version_1.1 version_1.2 ``` Is there a way of delting any file that starts with the name version? Thanks

Original source