count file

Gerhard Häring gerhard at bigfoot.de
Fri May 31 06:02:49 EDT 2002


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



More information about the Python-list mailing list