title: Create new Folder in Drive if it doesn't already exist
body: <p><strong>CONTEXT</strong></p>
  
  <p>In my Drive there's the following structure:</p>
  
  <blockquote>
    <p>Ops folder || Sales folder</p>
    
    <p>Ops contains 3 folders: Process1 / Process2 / Process3</p>
    
    <p>Sales contains 3 folders: Customer1 / Customer2 / Customer3</p>
  </blockquote>
  
  <p><strong>TARGET</strong></p>
  
  <p>I'm asking for the names of the folders in Drive > SALES</p>
  
  <p>In a Sheet I have a list of Names of some Prospects. I'm checking one by one if the name of the prospect matches with any folder in my Drive.</p>
  
  <p>In case there's a folder that matches the prospect name then do nothing.</p>
  
  <p>In case there's no folder for that Prospect I want to create a new folder in Sales with the prospect name</p>
  
  <pre><code>function prepararPropuesta() {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet()
    var ssAS = ss.getActiveSheet()
    var ssProspects = ss.getSheetByName('Prospects')
  
    var lr = ssProspects.getLastRow()
    var lc = ssProspects.getLastColumn()  
  
  
  
    // I'm looking for the column 'Prospect' in the Sheet
    for(i=2; i&lt;lc; i++){  
  
      var columnas = ssProspects.getRange(2, i).getValue()
      Logger.log(columnas)
  
    if(columnas == 'Nombre Prospect'){
  
       var colProspect = ssProspects.getRange(2, i).getColumn()
       Logger.log(colProspect)
    }
    }
  
  
  /*
       Now I'm looking for the names of the folders in my Drive
       This is looking in all my Drive. It would be nice to filter the 
  search and look just in SubFolders(Sales)
  */
     var folders = DriveApp.searchFolders('"me" in owners');
      while (folders.hasNext()) {
     var folder = folders.next();
     Logger.log(folder.getName());
  
  /*       The first Prospect Name is in row 2 and I'm creating a loop to 
  get each Name 
           If the name matches an existing Folder then ends the function
           If the Prospect Name is not found in the Folders list then creates a new Folder under the name prospectName
  */
        for(i=2; i&lt;lr; i++){
        var prospectName = ssProspects.getRange(i, colCliente).getValue()
  
              var folderName = folder.getName()
              if(folderName = prospectName){
  
                return
  
              }  
        }
  
  
        DriveApp.createFolder(prospectName)
  
  
  }
  }
  </code></pre>
  
  <p>In between the lines in the code you will find a description step by step</p>
  
  <p>(1) I'm finding the column in which the prospect names are -> This works fine</p>
  
  <p>(2) I'm using WHILE to get all the name folders in my Drive 
  This log</p>
  
  <pre><code>Logger.log(folder.getName())
  </code></pre>
  
  <p>Returns</p>
  
  <blockquote>
    <p>[18-04-21 06:33:35:985 PDT] FolderIterator</p>
  </blockquote>
  
  <p>Is it getting the names correctly?</p>
  
  <p>(3) I created the variables folderName and prospectName and looped them to check if there's a match -> This part doesn't work correctly. I guess that my I'm not using the right methods although I researched in developers.google. How could it be done?</p>
  
  <p>Thnx!</p>