os.mkdir('dir/all_files')
extensions = ['.csv']
for folder, _, filenames in os.walk(path):
    for filename in filenames:
        if folder == path or folder == os.path.join(path, 'all_files'):
            continue
folder = folder.strip(path)
extension = os.path.splitext(os.path.splitext(filename)[0])[-1].lower()
if extension in extensions:
    infilename = os.path.join(path, folder, filename)
newname = os.path.join(path, 'all_files', '{}-{}'.format(folder.strip('./'),
    filename.replace('.csv.bz2', '.csv')))
os.rename(infilename, newname)
Как переименовывать и перемещать файлы из разных каталогов в один общий каталог?