from os import listdir

for name in listdir( "C:\\Temp" ):
    print( name )

from os import walk

for root, dirs, files in walk( 'C:\\Temp', topdown=True ):
    print( root )
    print( dirs )
    print( files )
    print( '--------------------------------' )

from os import scandir

with scandir( "C:\\Temp" ) as it:
    for entry in it:
        print( entry.name )

from os import scandir

def filemap( path, action, is_target ):
    with scandir( path ) as it:
        for entry in it:
            if entry.is_dir():
                filemap( entry.path, action, is_target )
            elif is_target( entry ):
                action( entry )

filemap( "c:\\Temp",
         lambda e : print( e.name ),
         lambda e : e.name.lower().endswith( ".py" ) )

count = 0
def count_file( entry ):
    global count
    count += 1

filemap( "c:\\Temp",
         count_file,
         lambda e : e.name.lower().endswith( ".py" ) )
print( count )

class CountFile:
    def __init__( self ):
        self.__count = 0

    @property
    def count( self ):
        return self.__count

    def __call__( self, entry ):
        self.__count += 1

    def __str__( self ):
        return F"{self.__count}"

c = CountFile()
filemap( "c:\\Temp",
         c,
         lambda e : e.name.lower().endswith( ".py" ) )
print( c )

lambda e : e.name.lower().endswith( ".py" )

def endswith( *args ):
    extensions = [ ext.lower() for ext in args ]

    def _is_target( entry ):
        name = entry.name.lower()
        for ext in extensions:
            if name.endswith( ext ):
                return True
        return False

    return _is_target

c = CountFile()
filemap( "C:\\Tools\\Anaconda3",
         c,
         endswith( ".py", ".txt" ) )
print( c ) 

def older_than( day_count ):
    from datetime import datetime as DT,
                         timedelta, timezone
    today = DT.now()
    epoch = DT( 1970, 1, 1 )
    ref   = timedelta( hours = day_count * 24 )

    def _is_target( entry ):
        creation_date = epoch + timedelta( seconds = entry.stat().st_ctime )
        return ( today - creation_date ) >= ref

    return _is_target

filemap( "C:\\Temp",
         lambda e: unlink( e.path ),
         older_than( 30 ) )