1

Now, I need to upload the files in the entire Google drive to s3, and need to maintain the same directory structure as Google drive. When I get the file structure of Google drive, I found that I can only get files from the root directory layer by layer, so that I can get the files and file paths completely.

def get_folderid_path(self, parent):
    children = self.get_request(q="'%s' in parents" % parent)
    for child in children:
        child_id = child.get("id")
        child_name = child.get("name")
        child_mime_type = child.get("mimeType")
        if child_mime_type == "application/vnd.google-apps.folder":
            self.folder_path = self.test_list[-1] + "/" + child_name
            self.test_list.append(self.folder_path)
            self.folder_id_path_dict[child_id] = self.folder_path
            self.get_folderid_path(child_id)
        elif child_mime_type == "application/octet-stream" and child_name.endswith(
            ".side"
        ):
            child_file_list = self.folder_id_childlist_dict.get(parent, [])
            if not child_file_list:
                self.folder_id_childlist_dict[parent] = child_file_list
            child_file_list.append({"id": child_id, "name": child_name})

    if self.test_list:
        self.test_list.pop()

I use a recursive method, I do not know if there is a more convenient method.

McCray
  • 83
  • 1
  • 7
  • 2
    Although I'm not sure whether I could correctly understand about your goal, for example, is [this information](https://stackoverflow.com/q/41741520) useful for your situation? The python library for achieving this is [this](https://github.com/tanaikech/getfilelistpy). In this case, at first, the list of all files and folders is retrieved. Then, the folder structure is created from the retrieved list. By this, the cost will be lower than that of the method for requesting each folder. If this was not the direction you want, I apologize. – Tanaike Apr 15 '20 at 06:14
  • Thanks for your input, this really helped me. – McCray Apr 15 '20 at 09:34
  • Thank you for replying. I'm glad your issue was resolved. When your issue was resolved, can you post it as an answer? By this, it will help users who have the same issue. – Tanaike Apr 15 '20 at 22:20
  • Upvoting. There should be a "download as zip" option via API call too (it can be done in the browser by right clicking a "folder" and selecting "Download") – Visko Apr 16 '20 at 15:17

0 Answers0