Is it possible to change a google drive folder name from within appsheet app?

I have an app that uses google sheet as the datasource.

I have an api that initially creates a google drive folder (same account the appsheet app uses).  The url to the folder is stored in the data sheet and is referenced to display an image within a template that is emailed to the user.

There are a couple of scenarios where I would like to be able to change the folder name from within appsheet, from say, "acme1" to "acme2"

Is this possible?

0 11 276
11 REPLIES 11

Short answer: it should be possible, but I have not personally tested this. If you have the folder url stored in a column, then you should be able to extract just the ID of the folder. Then you should be able to set up a bot for probably a data change event on a column that ideally stores the folder name. The process should execute a Script that uses DriveApp.getFolderById(ID).setName(newname).

Interesting.

But I don't store the folder id in the column - just the actual folder path (from the root/default app folder).

The api that creates the folder is going to the appsheet app and is being created thru the app

 


@Appy wrote:

The url to the folder is stored in the data sheet


 

I went off of this statement that you actually had the url vs the folder path. But even then you could strip the folder name out of the folder path that is stored and then use Apps Script just do DriveApp.getFolderByName(foldername). However this returns an array of folders that match that name so then that would need to become DriveApp.getFolderByName(foldername).next().setName(newname). Again I have not used this myself so the testing would be up to you.

Thank you.

I'll give it a shot.

Keep in mind that getFolderByName() gets a random result set of folders with that name. So if this returns more than one folder, using next().setName() might not change the name of the folder you actually want to change. So in that sense if your API that creates the folder can handle return values and send back a folder ID that you can store in your data, that would be preferable.

I have not used Apps Script before. Its a little daunting at first blush. I am concerned that this is going to search my entire drive, and I have quite a few clones of the folder in multiple projects.

Do you have any tips on how to contain the script to the specific folder path?

I didn't see your response above before I posted this.

I don't think this approach is the most efficient for my needs.  My api can't handle a  return value.

Thank you for your input. I'll try another approach.

 

What API are you using to create the folder? Just curious so maybe I can propose some other possible solution. Do the folders have some form of standardized names like does the name contain the customer key column value that is a unique like value?

Hi,

I am using Power Automate Flow to create the folder path and drop the (2)images into it. (thru gdrive connector). The same flow then uses http connector to write the path to a column in the app's sheet (thru the app).

The path is standardized: /folder1/folder2/Sigs/customerkeycolumnvalue/AA2/

and the image filenames are standardized.

I found this script online to get to a Gdrive folder by using a path. I think it would still be easier to check your power automate connector to see if you can get the ID of the folder instead of the path and store that. You would still need to figure how to update the path which you could do in the script possibly or reconstruct your path string and off course passing a new name into the function. But ideally you would trigger the script from within Appsheet, return values back to the Appsheet process and use those return values to reset your column values.

function getDriveFolderFromPath(path, newname) {
  let folder = (path || "/").split("/").reduce(function(prev,current) {
    if (prev && current) {
      var fldrs = prev.getFoldersByName(current);
      return fldrs.hasNext() ? fldrs.next() : null;
    }
    else {
      return current ? null : prev;
    }
  },DriveApp.getRootFolder());

  folder.setName(newname);
}

Thank you for the snippet. 

I agree that it would be better to get the ID of the folder.  I am a little concerned about using the above snippet as it cycles thru all the folders and I have many folders with this same name  (probably over 500).

I appreciate your input.

Do all of the ~500 folder have the same path also? The code snippet is based on the path, so if none of the other folders share the same path you should be ok. But if they all have the same exact path that is a problem. I might suggest looking at your option from the Power BI perspective if you can return the Folder ID instead of a path through your process there.

Top Labels in this Space