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

Chris Angelico rosuav at gmail.com
Tue Nov 6 06:24:38 CET 2012


On Tue, Nov 6, 2012 at 4:19 PM, iMath <redstone-cold at 163.com> 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


More information about the Python-list mailing list