# Is there a way to append all materials in a Blender files with Python?

What I usually do is assign all my materials to a Cube and append it, and the materials just come with it.

The problem is that bpy.ops.wp.append() require a filename, and I have no way that I know to create a for loop that would cycle through all the mats in the file and append them. Usually when I want to import all files in a folder I use glob.glob() to create a list but that obviously wouldn't work in this case. Is there an equivalent to glob.glob() for a blend file?

Appending the cube has it's limit since I need to remember to assign my materials to it, and when you are working with hundreds of mats it becomes problematic.

Example using BlendDataLibraries based on How can I import BI materials from another blender file with python?. The script scans the given directory for blend files and appends all materials:

import bpy
import os

blend_files = []
for root, dirs, files in os.walk("/home/<USER>/..."):
for file in files:
if file.endswith(".blend"):
blend_files.append(os.path.join(root, file))

# Append all materials from all blends within the folder
for filepath in blend_files:

with bpy.data.libraries.load(filepath, link=False) as (data_from, data_to):