Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Copy data of specific files in specific sheets with Apps Script

This code search files inside a folder (files are filtered by sufix) and return a list with two columns, one for filenames and other of file IDs.

var ss = SpreadsheetApp.getActive();
var sh = SpreadsheetApp.getActiveSheet();
var FILES_FOLDER = DriveApp.getFolderById("FOLDER ID");
var sufix = 'TXT' // adapt as necessary
var list = [];
var files = FILES_FOLDER.getFiles();
while (files.hasNext()) {
  file = files.next();
  list.push([file.getName(),file.getId()])
}
var result = [['FILENAME','FILE_ID], ...list.filter(r => r[0].includes(sufix)).sort()]
sh.getRange(2,3, result.length, result[0].length).setValues(result);

Well, I need to copy the data of each .txt file in a specific sheet (that already exist) for each .txt. There are like 5 possible .txt files but the 5 are not always in the folder (sometimes 2, or 3) so I need the code to be versatile.

if (TXTFILE EXIST) {
var TXT_FILE = DriveApp.getFileById(FILE ID);
TXT_FILE.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
var tsvUrl = "https://drive.google.com/uc?id="+FILEID+"&x=.tsv";
var tsvContent = UrlFetchApp.fetch(tsvUrl,{muteHttpExceptions: true }).getContentText();
var tsvData = Utilities.parseCsv(tsvContent, '\t');

var sheet_SP = SpreadsheetApp.getActive().getSheetByName('SHEET_TO_COPY_DATA');
sheet_SP.getRange(1, 1, tsvData.length, tsvData[0].length).setValues(tsvData);
} else {
  return
}

I suppose is something like attach each filename to his ID, and then if file with X word in his filename exist then get his id from the previous list. Or maybe the SHEET NAME has to be also linked to the list for the iteration. I don't know which would be the cleanest way to do this.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda