'''
Created on Nov 19, 2013

@author: rcd
'''
import os
import tkFileDialog


def countFiles (folderName):
    count = 0
    # try only those files and folders that are not 'hidden'
    visibles = [ f for f in os.listdir(folderName) if not f.startswith('.') ]
    for fileORfold in visibles:
        # use the file's complete name
        path = os.path.join(folderName, fileORfold)
        # general case: it is a folder, so add its count to our own
        if os.path.isdir(path):
            count += countFiles(path)
        # base case: count this one single file
        else:
            count += 1
    # return our results to be combined with all the others
    return count


folderName = tkFileDialog.askdirectory(initialdir=os.getcwd())
print(countFiles(folderName))
