pygrep

Mike Brenner mikeb at mitre.org
Wed May 2 09:07:48 EDT 2001


This (perl and python) grep works like the unix grep, not
like the Windows grep. For example the one that for almost
20 years has come with all Borland software, and the ones
that are available on the bulletin boards. 

The windows versions come (or in Borland's case can be
configured to come) with the capability of searching all
subdirectories, which is very useful, without having to
program a FIND.

The line of code:
	for filename in sys.argv[2:]:

does not accept even starred names in the current directory
(e.g. *.txt or *.*) under windows, because it depends on the
operating systems having already expanded the star names in
the command line. 

This pre-expansion by the operating system is bad because
each installation of unix comes with a limiting parameter as
to how much can be expanded, and you always come across
directories that have more than that many files.

Therefore, it would be nice if Python had a way of expanding
the second argument, both the stars and question marks, and
also the ability to iterate through all files at all levels.
This would be WITHIN python, not depending on the operating
system to do it.

Mike Brenner





More information about the Python-list mailing list