Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'exception': 0.03; 'subject:How': 0.09; 'excluding': 0.09; 'subject:files': 0.09; '(note': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject: \n ': 0.16; 'subject:non': 0.16; 'wrote:': 0.17; 'directory.': 0.17; 'code,': 0.18; 'received:209.85.214.174': 0.21; 'second': 0.24; 'testing': 0.24; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'there.': 0.28; 'subject:list': 0.28; 'post': 0.28; 'code': 0.31; 'getting': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'list': 0.35; 'filter': 0.35; 'nov': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'step': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'skip:n 10': 0.63; 'difficulty': 0.65; 'subject:get': 0.81; 'fun!': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=SxytQXLOAYiDjgqGbdUri6Q9EA5S5eK567TkhOTxGdE=; b=t71xe+aBsqy6sLNJcUcFBfFDWCMXZIrJ0w8I6RoBeiS7HtPqShpX1PziVtt1fjNCML BI8Phh6zpYe6ynvXhE7z7bUK6m9sOsh7ndwJOmc+nahpM8Fmv35T9VO+U72ibvGlXJYv rMSAGEuNrbBsdV6AqZu8qOK7oytUrbnJUFjJJ99cVEhT1j5TwKqXk4tfLRfJrZs5iNDI Hh47dPb5843OhWUSAdEw0AA3HLcERy58GuBpjsmtqQDthWAPN94O450XDYXG+ulft/nS iwZ1KVLV11MErAZFiHlGK1a1/sEPaocJaiAHw5q6Bndzz6b8zajnOGpV5RpmSIZtDL/x Mf/A== MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 6 Nov 2012 16:24:38 +1100 Subject: Re: How to only get a list of the names of the non-directory files in current directory ('.')? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352179480 news.xs4all.nl 6978 [2001:888:2000:d::a6]:53671 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32805 On Tue, Nov 6, 2012 at 4:19 PM, iMath wrote: > How to only get a list of the names of the non-directory files in current directory ('.')? > (Note excluding its subdirectories ). > > I need the code : ) Start by getting a list of names of everything in the current directory. Then filter that list by testing each one to see if it's a directory. Tip: The second step can be done with os.path.isdir Put some code together and try it. If you have trouble, post your code, any exception traceback you get, and what you're having difficulty with, and we'll go on from there. Have fun! ChrisA