Currently I'm developing script that will perform cleanup of specific directories.
For example: Directory: /app/test/log contains many sub-directories with name pattern testYYYYMMDD and logYYYYMMDD
What I need, is to filter out only directories like testYYYYMMDD
To get all folders with absolute path that are in given directory I use:
folders_in_given_folder = [name for name in os.listdir(Directory) if os.path.isdir(os.path.join(Directory, name))] folder_list =  for folder in folders_in_given_folder: folder_list.append([os.path.join(Directory, folder)]) print(folder_list)
[['/app/test/log/test20150615'], ['/app/test/log/test20150616'], ['/app/test/log/b'], ['/app/test/log/a'], ['/app/test/log/New folder'], ['/app/test/log/rem'], ['/app/test/log/test']]
So now I need to filter out sub-directories that fits pattern, pattern can be something like: *test*, test*, test2015*
I've tried using glob.glob(), but this seems to work only with files not directories.
Could someone please be so kind and explain how I could achieve desired outcome?