Hi everyone,

I’m an absolute beginner in programming and I need some guiding.

This is what I want to do:

Copy a particular file located in a subfolder in Drive and paste it into multiple subfolders using Google Script.

This is what I’ve done so far:

function copyFilesintoMultipleFolders() {
  var srcFolder = DriveApp.getFolderById("XXXXXXXXXXXXXXXXXXXXXXXX")
  var dstFolder = DriveApp.getFolderById("YYYYYYYYYYYYYYYYYYYYYYYY")
  var file = DriveApp.getFileById("ZZZZZZZZZZZZZZZZZZZZZZZZ")
  while (dstFolder.hasNext()){
    var f = file.makeCopy(dstFolder)
    if (file.getMimeType() == MimeType.GOOGLE_APPS_SCRIPT){
      Drive.Files.update({"parents": [{"id": dstFolder}]}, f.getId());
    }                   

  } 

}

But I got stuck at the while loop because I get this error: “TypeError: Cannot find function hasNext”.

What did I do wrong? My dstFolder has multiple subfolders and I’ve tried to copy the file in all those multiple subfolders but I don’t know why hasNext doesn’t work.

Can anyone please guide me?

Much appreciated!

For clarity tell if Google Script is "Google Apps Script."

https://developers.google.com/apps-script/reference/drive/drive-app shows no method hasNext.

Sorry but I don't work with this often enough to write your app for you.

commented: Or is there another programming language that I can use to do this? I've tried Google Apps Script since it seemed to me a bit easier. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.