Remove items from a list
Elbert Lev
elbertlev at hotmail.com
Wed Sep 8 14:19:04 EDT 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
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