0
votes

I could find only ways to get the root folder id from google drive api -[REFERENCE]: Google Drive API v3 getting root folder Id in java . I have to get the folder id by giving a name. Is there anyway i could get Folder id of a directory in Drive by passing its name.

2

2 Answers

2
votes

You can search for a specific folder with these parameters:

name = 'your-folder-name'
mimeType = 'application/vnd.google-apps.folder'

The mime type makes sure, that you are only searching for folders. For more information, take a look at the documentation of the search parameters here.

1
votes

Use the following to find the folder id with folder name. if such folder is not found it will result folderId as 0.

let folderName = "myFolder";
let result = await drive.files.list({
    q: "mimeType='application/vnd.google-apps.folder' and trashed=false",
    fields: 'nextPageToken, files(id, name)',
    spaces: 'drive',
}).catch(e => console.log("eeee", e));
let folder = result.data.files.filter(x => x.name === folderName);
var folderId = folder.length?folder[0].id:0;
console.log(folder.id)