0
function copyFolderContents_(source, target) {
  // Iterate files in source folder
  const filesIterator = source.getFiles()
  while (filesIterator.hasNext()) {
    const file = filesIterator.next()

    // Make a copy of the file keeping the same name
    file.makeCopy(file.getName(), target)
  }
}

const toCopy = DriveApp.getFolderById('')
const copyInto = DriveApp.getFolderById('')
const newFolder = copyInto.createFolder(toCopy.getName())
copyFolderContents_(toCopy, newFolder)

Is it possible to let this run in my local machine? The API seems to be just controlling how the app script runs instead of letting you run the getFolderById makeCopy functions.

Luk Aron
  • 1,235
  • 11
  • 34
  • Does this answer your question? [Run app script function from website/localhost](https://stackoverflow.com/questions/42472349/run-app-script-function-from-website-localhost) – Kos Aug 11 '21 at 12:39

1 Answers1

2

No, Apps Script is run in google cloud servers, so you cannot run it directly in your local machine by default. Alternatively, you can access the functionality via APIs.

Basically, getFolderById and makeCopy are just wrappers for specific Drive APIs for it to be used easily on Apps Script.

To do the same thing above, you can use a combination of Files: list and Files: copy

Check API Reference for more info.

NightEye
  • 10,634
  • 2
  • 5
  • 24