Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Búsqueda de archivos basada en una matriz de nombres de archivos y recuperación de propiedades de archivos para registrarlos en una hoja - Google App Scripts

He estado tratando de resolver esto, pero soy nuevo en la programación. Quiero obtener todos los nombres de archivo de una carpeta temporal y filtrarlos con los nombres de archivo que se han registrado previamente en una hoja junto con otras propiedades de archivo (tamaño, fecha de modificación, identificación, URL).

Después de mantener solo los nombres de archivo en la matriz que aún no están en la lista, me gustaría recuperar los archivos que tienen estos nombres de mi carpeta temporal y obtener sus propiedades de archivo para agregar una nueva fila a la hoja con el nombre, tamaño, fecha de modificación, id, url).

Esto es lo que tengo hasta ahora:

 const invoiceLog = SpreadsheetApp.openById('SPREADSHEETID').getSheetByName('invoicedata'); const invoiceDispatcherLog = SpreadsheetApp.openById('SPREADSHEETID').getSheetByName('invoicedispatcherlog'); const tempInvoiceFolder = DriveApp.getFolderById('TEMPFOLDERID'); const invoiceFolder2021 = DriveApp.getFolderById('INVOICEFOLDERID'); function invoiceLogger () { // get new Invoices from tempFolder and make an array of their names let newInvoiceFileNames = []; let newInvoices = tempInvoiceFolder.getFiles(); while (newInvoices.hasNext()){ file =newInvoices.next(); let row = [] row.push(file.getName()) newInvoiceFileNames.push(row); Logger.log(row) } // filter the array of new invoices by existing invoice names in the invoice log let newInvoiceFileNamesFlat = newInvoiceFileNames.map(function(row) {return row [0];}); let existingInvoices = invoiceLog.getRange('A2:A').getValues(); let existingInvoicesFlat = existingInvoices.map(function(row) {return row [0];}); var cleanInvoiceNames = newInvoiceFileNamesFlat.filter(item => !existingInvoicesFlat.includes(item)) //let markedFiles = DriveApp.getFilesByName(cleanInvoiceNames); cleanInvoiceNames.forEach(SearchFiles)

Estoy seguro de que tengo algunas redundancias aquí y no estoy en un punto en el que pueda apreciar completamente todos los aspectos de cómo las funciones y los métodos se entrelazan, pero estaría enormemente agradecido por alguna orientación. Por favor, hágame saber si algo de esto no está claro y si puedo proporcionar más información.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Actualizar datos de factura

 function updateInvoiceData() { const ss = SpreadsheetApp.openById('ssid'); const ish = ss.getSheetByName('invoicedata'); const lnames = ish.getRange(2, 1, ish.getLastRow() - 1).getValues().filter(r => r[0]).flat();//listed names const ifldr = DriveApp.getFolderById('TEMPFOLDERID'); let info = [];//new names let ifiles = ifldr.getFiles(); while (ifiles.hasNext()) { let ifile = ifiles.next(); let n = ifile.getName(); //if not already listed if(!~lnames.indexOf(n)) { info.push([n, ifile.getSize(),ifile.getDateCreated(),ifile.getId(),ifile.getUrl()]); } } ish.getRange(ish.getLastRow() + 1,1,info.length,info[0].length).setValues(info); }

bit a bit no (~)

Esto obtiene la fecha de modificación:

 function updateInvoiceData() { const ss = SpreadsheetApp.openById(gobj.globals.ssid); const ish = ss.getSheetByName('Sheet0'); const sr = 2;//data start row const lr = ish.getLastRow();//data last row let lnames; if(lr > 1) { lnames = ish.getRange(2, 1, ish.getLastRow() - 1).getValues().filter(r => r[0]).flat();//listed names } else { lnames = []; } const ifldr = DriveApp.getFolderById(gobj.globals.testfolderid); let info = [];//new names let ifiles = ifldr.getFiles(); while (ifiles.hasNext()) { let ifile = ifiles.next(); let n = ifile.getName(); //if not already listed if(!~lnames.indexOf(n)) { let d = JSON.parse(Drive.Files.get(ifile.getId())).modifiedDate; info.push([n, ifile.getSize(),d,ifile.getId(),ifile.getUrl()]); } } ish.getRange(lr + 1,1,info.length,info[0].length).setValues(info); }

Tienes que habilitar Drive API versión 2

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!