Remove items from a list

Elbert Lev elbertlev at
Wed Sep 8 20:19:04 CEST 2004

"Stan Cook" <scook at> wrote in message news:<ysv%c.32876$Dl4.14767 at>...
> I was trying to take a list of files in a directory and remove all but 
> the ".dbf" files.  I used the following to try to remove the items, but 
> they would not remove.  Any help would be greatly appreciated.

# Assume we want files in working directory
import glob
import os.path

#If you want to have the list of dbf files try this:
lst = glob.glob("*.dbf")
print "lst = glob.glob(\"*.dbf\")"
print lst

# If you want to have the list of files, which do not have dbf extension:
lst = [x for x in glob.glob("*.*") if os.path.splitext(x) != "dbf"]
print "lst = [x for x in glob.glob(\"*.*\") if os.path.splitext(x) != \"dbf\"]"
print lst

More information about the Python-list mailing list