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


Groups > comp.lang.python > #83114

Re: How do I remove/unlink wildcarded files

Date 2015-01-02 13:36 +0100
From Ervin Hegedüs <airween@gmail.com>
Subject Re: How do I remove/unlink wildcarded files
References <20150102090051.GC22372@arxnet.hu> <20150102102153.GA89926@cskk.homeip.net> <20150102053552.6ed449b8@bigbox.christie.dr>
Newsgroups comp.lang.python
Message-ID <mailman.17321.1420202175.18130.python-list@python.org> (permalink)

Show all headers | View raw


Hi,

On Fri, Jan 02, 2015 at 05:35:52AM -0600, Tim Chase wrote:
> 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 :-)

yes, you're right - I've missed out a "." before the "*". :)



thanks:


a.


-- 
I � UTF-8

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


Thread

Re: How do I remove/unlink wildcarded files Ervin Hegedüs <airween@gmail.com> - 2015-01-02 13:36 +0100

csiph-web