How to separate directory list and file list?

Gonnasi harddong at 21cn.net
Mon Oct 24 09:07:04 EDT 2005


Lots of thanks for your help, My code can return the right result now.

Thanks again!

On Sun, 23 Oct 2005 17:27:49 +0200, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:

>"Gonnasi" wrote:
>
>> With
>> >glob.glob("*")
>>
>> or
>> >os.listdir(cwd)
>>
>> I can get a combined file list with directory list, but I just wanna a
>> bare file list, no directory list. How to get it?
>
>use os.path.isfile on the result.
>
>    for file in glob.glob("*"):
>        if not os.path.isfile(file):
>            continue
>        ... deal with file ...
>
>    for file in os.listdir(cwd):
>        file = os.path.join(cwd, file)
>        if not os.path.isfile(file):
>            continue
>        ... deal with file ...
>
>    files = map(os.path.isfile, glob.glob("*"))
>
>    files = (file for file in os.listdir(cwd) if os.path.isfile(os.path.join(cwd, file)))
>
>etc.
>
></F>
>
>




More information about the Python-list mailing list