K
K
KIRILL2019-04-18 16:09:39
Google
KIRILL, 2019-04-18 16:09:39

How to collect documents from google drive to google spreadsheet?

Hello, I want to ensure that data is entered into the Google spreadsheet:
1. File name
2. Link to the file
3. Creation
date 4. MimeType (this is Google doc or Google spreadsheet)
5. Creator name
6. Creator mail
xAeVw5etRROPKr.jpg
Previously, it was only required to enter only google spreadsheets, now - so that google documents are added.
But according to the current code, only tables are unloaded.

function fileInf() {
 currentSheet = SpreadsheetApp.getActiveSpreadsheet();
 var filesSheet = DriveApp.searchFiles('mimeType="application/vnd.google-apps.spreadsheet"');
 var filesDocs = DriveApp.searchFiles('mimeType="application/vnd.google-apps.document"');

 var i = 1;
 for (i = 1; i <= 500; i++) {
   filesSheet.hasNext();
   filesDocs.hasNext();
   var file = filesSheet.next() || filesDocs.next();
   currentSheet.getRange("A"+i).setValue(file.getName());
   currentSheet.getRange("B"+i).setValue(file.getDateCreated());
   currentSheet.getRange("C"+i).setValue(file.getOwner().getName());
   currentSheet.getRange("D"+i).setValue(file.getUrl());
   currentSheet.getRange("E"+i).setValue(file.getOwner().getEmail());
   currentSheet.getRange("F"+i).setValue(file.getMimeType());
 }
}

And is it possible, when it will be possible to upload a file type ( apl.../..document or apl.../..spreadsheet) to column F instead of this long file type name - it will only be Google Sheet or Google Document or other simplified names ?
Is it possible, in any way, to organize the following:
After the script does everything and brings everything in, a week will pass and new tables and new documents will appear, something will be deleted.
And how so that he correctly adds new ones and removes old ones, not on top of those already made, he brings in new ones again.
Roughly speaking data check.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor L, 2019-04-18
@Fzero0


And is it possible, when it will be possible to upload a file type ( apl.../..document or apl.../..spreadsheet) to column F instead of this long file type name - it will only be Google Sheet or Google Document or other simplified names ?
Well, you need to write a check function something like
function typeFile(type){
  var t = "Таблица";
  var n = "Что то другое";
  if(type="application/vnd.google-apps.spreadsheet"){
    return t
  }else{
    return n
  }
}

and then in currentSheet.getRange("F"+i).setValue(typeFile(file.getMimeType()));
well, you can also insert the formula instead of setValue and =IMAGE("your_icon_url",3)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question