getFolderById on object DriveApp.

36 views
Skip to first unread message

Iulian Kevin

unread,
Aug 24, 2022, 3:45:53 PM8/24/22
to Google Apps Script Community
Hello can some one help please ?

i'm getting this erorr..

I'm trying to do an automatic schedule save ( back -up)

New Bitmap Image.bmp

Paul Armstrong

unread,
Aug 24, 2022, 3:58:09 PM8/24/22
to Google Apps Script Community
Your folder Id is not valid.
It ends with "?this=true". That can't be right. 

Iulian Kevin

unread,
Aug 24, 2022, 4:02:07 PM8/24/22
to Google Apps Script Community
https://drive.google.com/drive/u/0/folders/1ApXGgAL9G5X8Wy9HBrKSbmHviLLjT_L8?ths=true    -  this is the folder url ...what should i copy ?

Paul Armstrong

unread,
Aug 24, 2022, 5:51:33 PM8/24/22
to Google Apps Script Community
It is my observation that a Drive ID, whether it be for a folder or a file, is only ever an alphanumeric value. Your value ends with a query string which makes it even less valid. 
Drop the ?ths=true. Leaving '1ApXGgAL9G5X8Wy9HBrKSbmHviLLjT_L8'

Paul Armstrong

unread,
Aug 24, 2022, 5:54:04 PM8/24/22
to Google Apps Script Community
I use this code to get an ID from a file or folder URL or a team drive.

getIdFromUrl(url) {
  var res;
  var m = url.match(/[-\w]{15,}/);
  if (m && m.length > 0) {
    res = m[0];
  }
  else if (url.length > 39) {
    // could be a teamdirve
   res = url.slice(39);
  }
return res;
}

Reply all
Reply to author
Forward
0 new messages