I want to get a list of all files and folders in the drive with a single request.
I provide this with a recursive function as follows, but as the number of files increases, it becomes impossible to use.
public function listDriveItemsRecursively($graph, $parentItemId)
{
$response = $graph->createRequest('GET', '/me/drive/items/' . $parentItemId . '/children')
->setReturnType(Model\DriveItem::class)
->execute();
$itemsObj = [];
foreach ($response as $item) {
$itemsObj[] = $item->getProperties();
}
$allItems = [];
foreach ($itemsObj as $item) {
if ($item['folder'] ?? null !== null) {
$allItems[] = $item;
$allItems = array_merge($allItems, $this->listDriveItemsRecursively($graph, $item['id']));
} else {
$allItems[] = $item;
}
}
return $allItems;
}
Anyone have a suggestion? Have a nice day.