count file

Gold Fish occeanlinux at linuxmail.org
Fri May 31 06:17:50 EDT 2002


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



More information about the Python-list mailing list