count file

Steve Holden sholden at holdenweb.com
Fri May 31 07:33:59 EDT 2002


"Gold Fish" <occeanlinux at linuxmail.org> wrote ...
> Gerhard Häring wrote:
>
> > In article <53HJ8.7782$fG3.277261 at news2.ulv.nextra.no>, Erlend J.
Leiknes
> > wrote:
> >> import os.path
> >> path = "/"
> >> items = os.path.listdir(path)
> >> myfiles = []
> >> for i in range(len(items):
> >>     if os.path.isfile(path + items[i]):
> >>         myfiles.append(path + items[i])
> >
> > It's better to use os.path.join to join path elements, as this will work
> > on any platform. There's no cross-platform way to get the root
directory,
> > though. On some platforms (Windows, for example), there might not even
be
> > a single root directory.
> >
> > Gerhard
> How about the directory have another subdirectory, i tried your way but it
> show an error when i got subdirectory in the original directory

Then you should use os.path.isdir() to check whether you are dealing with a
subdirectory and, if so, call your function recursively with the
subdirectory as an argument.

regards
 Steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list