K
K
keftrual2022-01-14 17:33:20
Google Drive
keftrual, 2022-01-14 17:33:20

How to transfer photos from one folder to another?

How to transfer photos from one folder to another, but this folder is created every time a new one. I have a script that simply transfers from one folder to another, but is it possible to somehow make this id, say, dynamic or something like that.

function CopyFiles() {
  var srcFldr = DriveApp.getFolderById("");
  var srcFiles = srcFldr.getFiles();
  var desFldr = DriveApp.getFolderById("");
  var desFiles = desFldr.getFiles();
  var dfnA = [];
  while (desFiles.hasNext()) {
    var df = desFiles.next();
    dfnA.push(df.getName());
  }
  while (srcFiles.hasNext()) {
    var sf = srcFiles.next();
    if (dfnA.indexOf(sf.getName()) == -1) {
      sf.makeCopy(sf.getName(), desFldr);
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2022-04-09
@keftrual

Specify Parameters for the Function

function copyFiles(fromId, toId) {
  var srcFldr = DriveApp.getFolderById(fromId);
  var srcFiles = srcFldr.getFiles();
  var desFldr = DriveApp.getFolderById(toId);
  var desFiles = desFldr.getFiles();
  var dfnA = [];
  while (desFiles.hasNext()) {
    var df = desFiles.next();
    dfnA.push(df.getName());
  }
  while (srcFiles.hasNext()) {
    var sf = srcFiles.next();
    if (dfnA.indexOf(sf.getName()) == -1) {
      sf.makeCopy(sf.getName(), desFldr);
    }
  }
}

function run(){
   copyFiles('ASDFASDFSDF2345234ADSFASDF', 'ASDFSDFasf452345345SAFDF-sagasdfASDF');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question