Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83113 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2015-01-02 05:35 -0600 |
| Last post | 2015-01-02 05:35 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How do I remove/unlink wildcarded files Tim Chase <python.list@tim.thechases.com> - 2015-01-02 05:35 -0600
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2015-01-02 05:35 -0600 |
| Subject | Re: How do I remove/unlink wildcarded files |
| Message-ID | <mailman.17320.1420198435.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web