'''
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


def listFiles (folderName, depth):
    results = []
    # 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) and depth > 1:
            results += listFiles(path, depth-1)
        # base case: count this one single file
        else:
            results += [ path ]
    # return our results to be combined with all the others
    return results


def bigFiles (folderName, minSize):
    results = []
    # 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 found items to our own
        if os.path.isdir(path):
            results += bigFiles(path, minSize)
        # base case: check this one single file
        elif os.path.exists(path):
            size = os.path.getsize(path)
            if size > minSize:
                results += [ (size, path) ]
    # return our results to be combined with all the others
    return results


def maxSize (folderName):
    results = (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 found items to our own
        if os.path.isdir(path):
            results = max(results, maxSize(path))
        # base case: check this one single file
        elif os.path.exists(path):
            size = os.path.getsize(path)
            results = max(results, (size, path))
    # return our results to be combined with all the others
    return results



folderName = tkFileDialog.askdirectory(initialdir=os.getcwd())
print(countFiles(folderName))
print(listFiles(folderName, 1))
print(bigFiles(folderName, 1000))
print(maxSize(folderName))
