Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to only get a list of the names of the non-directory files in current directory ('.')?

63 views
Skip to first unread message

iMath

unread,
Nov 6, 2012, 12:19:58 AM11/6/12
to
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 : )

Chris Angelico

unread,
Nov 6, 2012, 12:24:38 AM11/6/12
to pytho...@python.org
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

iMath

unread,
Nov 6, 2012, 6:12:46 PM11/6/12
to pytho...@python.org
在 2012年11月6日星期二UTC+8下午1时24分41秒,Chris Angelico写道:
how to get a list of names of everything in the current directory ?

iMath

unread,
Nov 6, 2012, 6:12:46 PM11/6/12
to comp.lan...@googlegroups.com, pytho...@python.org
在 2012年11月6日星期二UTC+8下午1时24分41秒,Chris Angelico写道:
how to get a list of names of everything in the current directory ?

John Gordon

unread,
Nov 6, 2012, 6:23:07 PM11/6/12
to
In <mailman.3345.1352243...@python.org> iMath <redsto...@163.com> writes:

> how to get a list of names of everything in the current directory ?

Try os.listdir() .

--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Prasad, Ramit

unread,
Nov 6, 2012, 6:41:53 PM11/6/12
to iMath, pytho...@python.org
iMath wrote:
> how to get a list of names of everything in the current directory ?

http://lmgtfy.com/?q=python+get+files+in+directory


~Ramit



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.

emile

unread,
Nov 13, 2012, 1:16:45 PM11/13/12
to pytho...@python.org
On 11/06/2012 03:12 PM, iMath wrote:

> how to get a list of names of everything in the current directory ?

Start by working through the tutorial to get familiar with python at
http://docs.python.org/2/tutorial/

then for your specific question, review the content at
http://www.diveintopython.net/file_handling/os_module.html

Emile


BTW, googling for "python how to get a list of names of everything in
the current directory" yields some good information as well. Google is
your friend for this level of question. Not sure anymore beyond that...





Chris Angelico

unread,
Nov 13, 2012, 3:53:21 PM11/13/12
to pytho...@python.org
On Wed, Nov 14, 2012 at 5:16 AM, emile <em...@fenx.com> wrote:
> BTW, googling for "python how to get a list of names of everything in the
> current directory" yields some good information as well. Google is your
> friend for this level of question. Not sure anymore beyond that...

It yields it? You mean Google is an iterator?

</troll>

John Gordon

unread,
Nov 13, 2012, 4:05:48 PM11/13/12
to
In <mailman.3644.1352840...@python.org> Chris Angelico <ros...@gmail.com> writes:

> It yields it? You mean Google is an iterator?

ITYM generator.

Chris Angelico

unread,
Nov 13, 2012, 4:19:13 PM11/13/12
to pytho...@python.org
On Wed, Nov 14, 2012 at 8:05 AM, John Gordon <gor...@panix.com> wrote:
> In <mailman.3644.1352840...@python.org> Chris Angelico <ros...@gmail.com> writes:
>
>> It yields it? You mean Google is an iterator?
>
> ITYM generator.

Yeah, that thing.

Troll fail.

*whoops*

ChrisA

emile

unread,
Nov 13, 2012, 4:24:51 PM11/13/12
to pytho...@python.org
On 11/13/2012 01:19 PM, Chris Angelico wrote:
> Troll fail.
>
> *whoops*

*sigh* mine too.

Emile


0 new messages