Instruction DriveApp.searchfiles

0

In Google App Script I am doing an algorithm that consists in searching a file in the google drive and recording its URL for future use. To find the file I use the following sequence of instructions:

var files = DriveApp.searchFiles('title contains variable');
while (files.hasNext())
{
  var file = files.next();   
  var dato = file.getUrl();
}

A variable that has a string of text inside is the name of the file that I want to search.

This instruction does not work for me. However, if I put in the place where the variable is the name I want to find in double quotes, everything works correctly. But the name I want to search can not be typed because I want to do it automatically without needing to write the name. And that name is within the value of the variable. Also, within a variable is the name in double quotes because it recognizes it as a text string.

I have tried writing variable without quotes like this in the example, in double quotes ("variable"), in single quotes ('variable') and none of the 3 works.

Can you tell me how I can make the instruction take variable and work?

    
asked by Marcelo 13.09.2017 в 02:17
source

3 answers

0

The handling of text strings in Google Apps Script is the same as in JavaScript. Use the + operator to concatenate two strings. In the case of a literal and a variable, it would be like this

'esta es una cadena literal ' + variable

Applying the above to the OP code

var variable = 'nombre';
var files = DriveApp.searchFiles('title contains ' + variable);
while (files.hasNext())
{
  var file = files.next();   
  var dato = file.getUrl();
}
    
answered by 14.09.2017 в 16:48
0

It works for me in the following way:

var files = DriveApp.searchFiles('title contains "' + variable + '"');

by putting the variable in double quotes.

    
answered by 28.06.2018 в 16:38
-1

If I understood what you want to do, is it add a variable where text should go?

For example in the setAttribute method:

window.addEventListener("DOMContentLoaded",function(){
console.log("Función realiza, DOM CARGADO..")
var divEjemplo = document.getElementById("ejemplo");
var atributo = "2px solid purple";
divEjemplo.setAttribute("style",'border: '+atributo+''); /* Aquí va la magia */
});
#ejemplo { width:300px;height:300px;background-color:lightpink;border-radius:150px; }
<div id="ejemplo"></div>

You add EQUAL quotes and the operator + BEFORE AND AFTER OF THE VARIABLE, 'texto: '+variable+'';

    
answered by 13.09.2017 в 02:54