I have backup directory structure like this (all directories are not empty):
/home/backups/mysql/
2012/
12/
15/
2013/
04/
You can use glob to search down a directory tree, like this:
import os, glob
def get_all_backup_paths(dir, level):
pattern = dir + level * '/*'
return [d for d in glob.glob(pattern) if os.path.isdir(d)]
I included a check for directories as well, in case there might be files mixed in with the directories.