Independentsoft
Professional software libraries for developers
Home
Purchase
Support
Company
Contact
Graph C++
>
Tutorial
> List entire drive
List entire drive recursively.
C++ example
#include
#include
#include
#include "independentsoft/graph/graph_client.hpp" #include "independentsoft/graph/graph_exception.hpp" #include "independentsoft/graph/files/drive_item.hpp" #include "independentsoft/graph/files/folder_properties.hpp" #include "independentsoft/graph/files/get_drive_items_response.hpp" #include "independentsoft/graph/files/drive_id.hpp" using namespace independentsoft::graph; using namespace independentsoft::graph::files; static void list_folder(GraphClient& client, std::vector
& all_items, const std::string& id, const DriveId& drive_id) { std::vector
sub_folders; GetDriveItemsResponse response = sync_wait(client.get_drive_items(id, drive_id)); while (true) { for (const DriveItem& item : response.drive_items) { all_items.push_back(item); if (item.folder_properties) { sub_folders.push_back(item); } } if (response.next_link.empty()) { break; } else { response = sync_wait(client.get_drive_items(response.next_link)); } } for (const DriveItem& item : sub_folders) { list_folder(client, all_items, item.id, drive_id); } } int main() { try { GraphClient client; client.client_id = "63333333-209e-454e-b7bd-55a4d201270f"; client.tenant = "independentsoft.onmicrosoft.com"; client.client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; std::vector
all_items; list_folder(client, all_items, "/", DriveId("b!T7ZW_FMzJ02x_G6HteZHZ")); for (const DriveItem& item : all_items) { std::cout << "Id: " << item.id << std::endl; std::cout << "Name: " << item.name << std::endl; std::cout << "WebUrl: " << item.web_url << std::endl; if (item.folder_properties) { std::cout << "Folder: true" << std::endl; } std::cout << "-----------------------------------------------------------------" << std::endl; } } catch (const GraphException& ex) { std::cout << "Error: " << ex.code << std::endl; std::cout << "Message: " << ex.message << std::endl; } return 0; }
Need help? Ask our developers:
Name*
Email*
Message*