-1

Let say I have some folders in SharePoint.

Each folder contains Folder1->Folder2>Folder3....>File(txt.docx etc) like this inside folder we have another folder and at the end some files of any type.

I want to access the files available in each folder with help of microsoft graph API in java sdk.

Below code will give me the root level files

JsonObject rootChildJson = graphClient.customRequest("/drives/"+driveId+
                          "/items/root/children") .buildRequest() .get();

and with the help of each item id of root folder I can get the next level file.

JsonObject innerChildren =graphClient.customRequest("/drives/"+driveId+
                                  "/items/"+itemId+"/children") .buildRequest() .get();

Is there an easy way to traverse the files available in each folder?

Thanks!!!

varsha
  • 63
  • 5

1 Answers1

0

Use the path

drives/{drive-id}/root:/{path-to-directory}:/children
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • Thanks!! Here what will be the {path-to-directory} value in my case? – varsha Feb 19 '21 at 12:02
  • folder1/folder2/folder3 etc – Hong Ooi Feb 19 '21 at 12:28
  • I am not sure about the path it should be dynamic one for just understanding purpose I have posted it in question. Path is not known in that case how we can access? – varsha Feb 19 '21 at 12:33
  • @varsha You can get the `path` from the parent path. For example, If you get the root files from `drives/{drive-id}/root/children`, the next level path should be `drives/{drive-id}/root:/{folder name}:/children`. You can loop the folders and list all the files. – Allen Wu Feb 22 '21 at 01:59