Question: I need to read the folders, subfolders and files from a Google Drive and create the respective hierarchy (of folders, subfolders and files) in my file system, with empty files (I only want to keep the names, not the data of the files). Pretty much like if I downloaded everything, but with only empty files and without having to download the whole files.

My goal is to have the complete hierarchy locally to work on it with other programs that use the file system (folders, subfolders and files) as an input.

My problem is that Google Drive API seems to be based on IDs (labels) and does not seem to have a hierarchy/path. I though of either listing all files and finding those that have parents, and creating the whole hierarchy myself (does not seem like a wonderful idea), or start with the root files and use `com.google.api.services.drive.Drive.Children` to recursively create my folders and files from the files that have the root as a parent (I had problem with that one, as I cannot seem to find the maven dependency for it).

Would you have a better idea or do you know if a solution already exist for this? I cannot seem to find anything on the Google Drive documentation that is related to this (and the exemples almost never have the correct Maven dependencies).

Thank you anyway for your time.

Example:
On Google Drive

```
file1.parent is folder1
file2.parent is root
folder1.parent is root

```

Should appear like this on the local file system (it could be in a temp folder).

```
root/
    folder1/
        file1
    file2

```

Answer: 
Quick start guide for java - <https://developers.google.com/drive/v3/web/quickstart/java>.

They use gradle. If you prefer maven use the following dependencies:

```
<dependencies>
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-drive</artifactId>
        <version>v3-rev22-1.21.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.oauth-client</groupId>
        <artifactId>google-oauth-client</artifactId>
        <version>1.21.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.oauth-client</groupId>
        <artifactId>google-oauth-client-jetty</artifactId>
        <version>1.21.0</version>
    </dependency>

</dependencies>

```

This will give you the working example (took me 10 minutes to run). Now let's get to the hierarchy problem. You'll have to use the **files.list** method and specify the search query. List of supported query parameters is here - <https://developers.google.com/drive/v3/web/search-parameters>.

So, you start from the root like this:

```
    FileList result = service.files().list()
            .setQ("'root' in parents and trashed = false")
            .setPageSize(100)
            .setFields("nextPageToken, files(id, name, mimeType)")
            .execute();

```

Then recursively build the hierarchy by using the folder ids instead of 'root' in the query. You can tell whether the given file resource is a folder or a file by looking at its mimeType property - mime type for a folder is **application/vnd.google-apps.folder**.
You may need to consider using available scopes like requesting full drive scope since you have the need related to listing or reorganizing files in user's Drive as discussed in [Choose Auth Scopes](https://developers.google.com/drive/v2/web/scopes#top_of_page)

Request format:

```
(https://www.googleapis.com/auth/drive)

```

On the other hand, you may also retrieve a list of your files by sending HTTP request with all the applicable parameters given in [Files: list](https://developers.google.com/drive/v2/reference/files/list#top_of_page).