i'm trying to use this code in a foreach the code looks a bit like this
subfolders = [ f.path for f in os.scandir(path_docs) if f.is_dir() ]
for x in subfolders:
arr = x.split('\\')
folder = arr[len(arr) - 1]
reader = llama_index.SimpleDirectoryReader(input_dir=os.path.join(path_docs,folder))
documents = reader.load_data()
parser = SentenceSplitter()
nodes = parser.get_nodes_from_documents(documents)
# initialize storage context (by default it's in-memory)
storage_context = StorageContext.from_defaults(persist_dir= path_docs)
storage_context.docstore.add_documents(nodes)
index = llama_index.load_index_from_storage(storage_context=storage_context)
indexed = True
and you can guess it only works for the last document since the storage_context is reset every loop