1

How do you remove files given a filespec such as "*.obj" on Windows? I'm using Windows 7 and 8.1 at the moment. Evidently os.remove does not take filespecs ("filespec" being a crude regular-expression for including wildcards such as *.txt to mean all files that end with ".txt").

Joey
  • 344,408
  • 85
  • 689
  • 683
JamesWHurst
  • 493
  • 8
  • 14
  • First [get a list of those files](http://stackoverflow.com/q/2225564/73070), then remove them. – Joey Jul 25 '14 at 06:01
  • XY problem - you want to find the list of files matching a wildcard, what you do with that list is a separate issue. – dnozay Jul 25 '14 at 06:11

1 Answers1

3

The python glob module provides wildcard file matching. So

import glob
import os
for f in glob.glob("*.obj"):
    os.remove(f)
Andrew Johnson
  • 3,078
  • 1
  • 18
  • 24