Globbing

Rahul Siddharthan rsidd120 at gmail.com
Thu Feb 14 09:17:40 PST 2008


Oliver Fromme wrote:
> > This would be the Python way to do it, just for the record:
> >
> > [x for x in listdir(".") if exists(x + "c")]
>
>Uhm, I'm sorry, the question was to find those files for
>which there is _no_ .elc file.  So there's a negation
>missing:
>
>[x for x in listdir(".") if not exists(x + "c")]

Actually you only want .el files that lack .elc files.  So it would be
  [x for x in listdir(".") if x[-3:]==".el" and not exists(x + "c")]

But the question was to find such all such files in a directory tree,
not just in the current directory.  I don't know whether there is a
python builtin for recursive directory listings, but it is trivial to
write one, so the above would work for that too.

(also, exists should be path.exists or os.path.exists depending on how
os was imported.  But it seems wasteful to use it since we only need
the directory listing.  I'd store the directory listing in a separate
variable and check for existence in that.)

I did say I'd do it in python, and list comprehensions are the number
two reason why I like python.  The overall clean syntax is the number
one reason.

Rahul





More information about the Kernel mailing list