Find a subfolder in the given directory that contains a Freesurfer
    anatomy (this may be the directory itself). Currently, the test is whether
    there are sub-folders with name 'surf' and 'mri'. Processes all sub-folders
    recursively until a freesurfer directory is found. If no matching folder is
    found the result is None.

    Parameters
    ----------
    directory : string
        Directory on local disk containing unpacked files

    Returns
    -------
    string
        Sub-directory containing a Freesurfer files or None if no such
        directory is found.

def get_freesurfer_dir(directory):
    """Find a subfolder in the given directory that contains a Freesurfer
    anatomy (this may be the directory itself). Currently, the test is whether
    there are sub-folders with name 'surf' and 'mri'. Processes all sub-folders
    recursively until a freesurfer directory is found. If no matching folder is
    found the result is None.

    Parameters
    ----------
    directory : string
        Directory on local disk containing unpacked files

    Returns
    -------
    string
        Sub-directory containing a Freesurfer files or None if no such
        directory is found.
    """
    dir_files = [f for f in os.listdir(directory)]
    # Look for sub-folders 'surf' and 'mri'
    if 'surf' in dir_files and 'mri' in dir_files:
        return directory
    # Directory is not a valid freesurfer directory. Continue to search
    # recursively until a matching directory is found.
    for f in os.listdir(directory):
        sub_dir = os.path.join(directory, f)
        if os.path.isdir(sub_dir):
            if get_freesurfer_dir(sub_dir):
                return sub_dir
    # The given directory does not contain a freesurfer anatomy directory
    return None