Search code examples
javascriptgoogle-apps-scriptgoogle-sheetsgoogle-apps

Google Scripts If filename contains x string log "x was found" missing bracket?


I'm attempting to search through all of my files and see if any of the files have a specified string inside of their filename. The script will then return that X file was found. Later on, I hope to use indexOf to return "x file was found at position y in array"

function myFunction() {

  var response = "Current"
  var files = DriveApp.getFiles();

  while (files.hasNext()) {
   var file = files.next();
   Logger.log(file.getName());

if(file.toString().indexOf(response)){
   Logger.log("the file" + file + "has been found at" response)};
}

When I run the program I receive the error message that I'm missing a ')' at the end of the last line. Am I missing something here?


Solution

  • You are missing a + in the last log, the compiler looks for the end of argument, while it actually continues. Your code:

    Logger.log("the file" + file + "has been found at" response)};
    

    Should be

    Logger.log("the file" + file + "has been found at" + response)};