Globbing

Oliver Fromme check+jw8ofi00rs0jv7gg at fromme.com
Thu Feb 14 09:35:03 PST 2008


Rahul Siddharthan wrote:
 > 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")]

Yup.  Sorry.

 > But the question was to find such all such files in a directory tree,
 > not just in the current directory.

No, the original question mentioned only a single directory.
Someone lese then asked about a directory tree.

 > I don't know whether there is a
 > python builtin for recursive directory listings,

Yes:  walk().  It's in module os, too.

 > (also, exists should be path.exists or os.path.exists depending on how
 > os was imported.

Yes, I assumed "from os import *" etc.

 > 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.)

That's also true.  :-)

dir = listdir(".")
[x for x in dir if x.endswith(".el") and x + "c" not in dir]

 > 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.

I agree 100%.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd





More information about the Kernel mailing list