Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'utf-8': 0.07; 'filename': 0.09; 'subject:files': 0.09; 'subject:How': 0.10; 'cc:addr:python- list': 0.11; 'jan': 0.12; 'missed': 0.12; '"."': 0.16; 'dirname': 0.16; 'expression.': 0.16; 'simpson': 0.16; 'subject:remove': 0.16; 'to:addr:python.list': 0.16; 'to:addr:tim.thechases.com': 0.16; 'to:name:tim chase': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; "doesn't": 0.30; 'chase': 0.31; 'file': 0.32; 'regular': 0.32; 'fri,': 0.33; 'received:google.com': 0.35; 'hi,': 0.36; 'skip:o 20': 0.38; 'anything': 0.39; 'expensive': 0.39; 'delete': 0.39; 'skip:u 10': 0.60; 'skip:o 30': 0.61; 'from:charset:utf-8': 0.61; "you're": 0.61; 'content-disposition:inline': 0.62; 'sound': 0.68; '2015': 0.84; 'received:hu': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=OtpPmHin1e1MKzYGf2RW2GPvM/9w5Gi/SxhB5D2pXK4=; b=wDdRr2ie8EipGHjyIJW7QURhz7a2GejypQ2dmwJS3fTJrAIs7rUPfjzdHPPBBabioU QV2CA1xJiq36ZKXZkNyDMgDOwhsbvCoBghWlrdxTPj03xTzNFMIHpitfuNiYJ72mIvOz NM6g1N3xKBxP8vq/7cujwSOJPKUrWUuYfAbC8DVetZQArnzWQ+Ur9Y4XK5XvWxjmU1Qx +30902x4lwvyEl1vdQUfMLggFcghAWyWidqak6+hdrNWi28WLHjnDc1y5w30A5IoSxbr GHpmSZFQJ4QdlyiPZGwRB7O7pjcxc2/YzTMS2uIp6UTz8uNS2ygJ30dXSDpIB1Hn3Im1 KVgA== X-Received: by 10.194.110.69 with SMTP id hy5mr151919519wjb.121.1420202167651; Fri, 02 Jan 2015 04:36:07 -0800 (PST) Date: Fri, 2 Jan 2015 13:36:04 +0100 From: Ervin =?utf-8?Q?Heged=C3=BCs?= To: Tim Chase Subject: Re: How do I remove/unlink wildcarded files References: <20150102090051.GC22372@arxnet.hu> <20150102102153.GA89926@cskk.homeip.net> <20150102053552.6ed449b8@bigbox.christie.dr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150102053552.6ed449b8@bigbox.christie.dr> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420202175 news.xs4all.nl 2895 [2001:888:2000:d::a6]:41084 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83114 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