<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def input_dir(dirname):
 """ Check all Python source files in this directory and all subdirectories. """

    dirname = dirname.rstrip('/')
    if excluded(dirname):
        return 0
    errors = 0
    for root, dirs, files in os.walk(dirname):
        if options.verbose:
            message('directory ' + root)
        options.counters['directories'] = \
            options.counters.get('directories', 0) + 1
        dirs.sort()
        for subdir in dirs:
            if excluded(subdir):
                dirs.remove(subdir)
        files.sort()
        for filename in files:
            errors += input_file(os.path.join(root, filename))
    return errors