pygrep

Steve Holden sholden at holdenweb.com
Wed May 2 10:10:51 EDT 2001


"Mike Brenner" <mikeb at mitre.org> wrote ...
> 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.
>
See the glob library module for this capability. There's the question then,
of course, of whether you inhibit globbing in Unix because the shell has
already done it ... the whole thing really is a little vexing, but the
ground was covered in a thread about two weeks ago. Try searching Google for
"Python glob" or some such.

regards
 Steve





More information about the Python-list mailing list