Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 获取Gscript文件夹和子文件夹中的所有文件_Google Apps Script - Fatal编程技术网

Google apps script 获取Gscript文件夹和子文件夹中的所有文件

Google apps script 获取Gscript文件夹和子文件夹中的所有文件,google-apps-script,Google Apps Script,我有一个gscript,它将返回文件夹中的所有文件并写入打开的电子表格。我想在所有的子文件夹中添加文件,但不能完全让它工作。以下是包含子文件夹内容的文件夹中文件的脚本: function getFiles() { // Get the active spreadsheet file and the active sheet var ss = SpreadsheetApp.getActiveSpreadsheet(); var ssid = ss.getId(); // Loo

我有一个gscript,它将返回文件夹中的所有文件并写入打开的电子表格。我想在所有的子文件夹中添加文件,但不能完全让它工作。以下是包含子文件夹内容的文件夹中文件的脚本:

function getFiles() {

  // Get the active spreadsheet file and the active sheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ssid = ss.getId();

  // Look in the current folder e.g. if this spreadsheet is in 'My Folder'
  // this routine will return all of the files in 'My Folder'.
  var ssparents = DriveApp.getFileById(ssid).getParents();
  var sheet = ss.getActiveSheet();

  // Clear the area, add the headers ready for results
  var headers = [["Full Folder Ref", "File Name", "Last Updated", "File Owner", "File URL", "In Folder"]];
  sheet.getRange("A1:F").clear();
  sheet.getRange("A1:F1").setValues(headers);

  // Loop through all the files, add the values to the spreadsheet.
  var folder = ssparents.next();
  var files = folder.getFiles();

  var i=1;
  while(files.hasNext()) {
    var file = files.next();

  // get the full folder ref
  var fileParents = file.getParents()
    folders = [];
    while (fileParents.hasNext()) {
      fileParents = fileParents.next();
      folders.push(fileParents.getName());
      fileParents = fileParents.getParents();
    }

  // create the row
    if(ss.getId() == file.getId()){ 
      continue; 
    }
    sheet.getRange(i+1, 1, 1, 6).setValues([[folders.reverse().join("/") , file.getName(), file.getLastUpdated(),file.getOwner().getName(), file.getUrl(), folder.getName()  ]]);
    i++;
  }
}
有人能帮我添加子文件夹文件吗


谢谢你

看看这个:这能回答你的问题吗?谢谢你们两位,我认为这可能会有所帮助,但我必须认真思考,因为我的编码技能已经过时了,我必须将其融入到上面的代码中。我已经尝试使用示例来实现这一点,但无法完全实现。我知道这是作弊,但如果有人有时间编辑我上面的例行公事,让我看看是怎么做的,我会非常高兴的。非常感谢。