Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83113

Re: How do I remove/unlink wildcarded files

Date 2015-01-02 05:35 -0600
From Tim Chase <python.list@tim.thechases.com>
Subject Re: How do I remove/unlink wildcarded files
References <20150102090051.GC22372@arxnet.hu> <20150102102153.GA89926@cskk.homeip.net>
Newsgroups comp.lang.python
Message-ID <mailman.17320.1420198435.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2015-01-02 21:21, Cameron Simpson wrote:
> >def unlinkFiles():
> >    dirname = "/path/to/dir"
> >    for f in os.listdir(dirname):
> >        if re.match("^unix*$", f):
> >            os.remove(os.path.join(dirname, f))
> 
> That is a very expensive way to check the filename in this
> particular case. Consider:
> 
>   if f.startswith('unix'):
> 
> instead of using a regular expression.

And worse, the given re would delete a file named "uni" which doesn't
sound ANYTHING like what the OP wanted :-)

-tkc

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How do I remove/unlink wildcarded files Tim Chase <python.list@tim.thechases.com> - 2015-01-02 05:35 -0600

csiph-web