How to create a folder if it doesn't exist?

前端 未结 5 1782
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 03:20

I\'m trying to create a folder if it doesn\'t exist, but the code creates a new folder every time I run it. I don´t know if my code is right.

Here is my code:

5条回答
  •  清酒与你
    2021-01-12 03:50

    As of Google Apps Script code in 2016 Aug

    var par_fdr = DriveApp.getFolderById(123456789A); // replace the ID
    var fdr_name = "child_fdr";
    
    try {
      var newFdr = par_fdr.getFoldersByName(fdr_name).next();
    }
    catch(e) {
      var newFdr = par_fdr.createFolder(fdr_name);
    }
    

提交回复
热议问题