Remove items from a list
elbertlev at hotmail.com
Wed Sep 8 20:19:04 CEST 2004
"Stan Cook" <scook at elp.rr.com> wrote in message news:<ysv%c.32876$Dl4.14767 at fe2.texas.rr.com>...
> 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
#If you want to have the list of dbf files try this:
lst = glob.glob("*.dbf")
print "lst = glob.glob(\"*.dbf\")"
# 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\"]"
More information about the Python-list