im simple message default title
PostgreSQL coub css express.js freeware git jquery laravel links linux macos mysql node.js php python task1 ubuntu vim virtualbox анекдот игры интересно музыка стихи цитаты

Python: рекурсивный проход по папкам August 26, 2009

Простенько двигаемся по папочкам и просто так считаем чего сколько. Для *nix придется сменить слеш в пути. А работать всё равно будет.

import os   
# settings: src dir 
sSrc='d:\\Install'   

def show_all(sSrc,iDirs=0,iFiles=0): 
    for file in os.listdir(sSrc): 
        # full pathname  
        file=os.path.join(sSrc,file)   
        if os.path.isdir(file): 
            # if directories 
            print '['+file+']' 
            iDirs+=1 
            iDirs,iFiles=show_all(file,iDirs,iFiles) 
        else: 
            # else files 
            print ' '+file 
            iFiles+=1 
    return iDirs,iFiles

iDirs,iFiles=show_all(sSrc,0,0)   

print """
total dirs: """,iDirs,""" 
total files: """,iFiles
python

Comments

No comments here yet.
You have to login to post a new comment.
HO-HO-HO!! L10 is here.
dance-dance #3
update new 01.10.2023