title: Google scripts, get a drive file url
body: <p>I need my script to load the URL of a drive file to be added to a spreadsheet. For whatever reason 'File.getUrl()' returns null, but everything else seems to be working.</p>
  
  <p>For example, 'File.getName()' works. So am I missing a permission or something?</p>
  
  <p>Here is my code (abridged):</p>
  
  <pre><code>function loadURL(folderPath, name) {       
    var folder = loadFolder(folderPath);
  
    // Find file
    var files = folder.searchFiles('modifiedDate &gt;= "' + getDate() + '" and title = "' + name + '"'),
        file, found = 0;
  
    for (; files.hasNext(); found++) {
      file = files.next();
    }
  
    if (found == 1) {
      /////////////////////////////////
      // Here is 'getUrl'
      /////////////////////////////////
      var url = file.getUrl();
  
      Logger.log("Loaded: " + url);
      return url;
    } else {
      throw "Error loading file";
    }
  }
  
  /**
  * ** NOTE: THIS SEEMS TO BE WORKING FINE **
  * Load a folder
  * @param {string} url
  * @return {Folder}
  */
  function loadFolder(url) {
    var folders = url.split('/'),
        folder = DriveApp.getRootFolder();
  
    Logger.log("Loading URL: " + url);
  
    for (var key in folders) {
      var fName = folders[key];    
      if (fName.length &gt; 0) {
        var fIt = folder.getFoldersByName(fName),
            found = 0;
  
        Logger.log(" -&gt; " + fName);
  
        for (; fIt.hasNext(); found++) {
          folder = fIt.next();
        }
  
        if (found == 0) {
          throw "Could not find the folder '" + fName + "'";
        } else if (found &gt; 1) {
          throw "Found multiple matches to the folder '" + fName + "'";
        }
      }
    }
  
    return folder;
  }
  </code></pre>
  
  <p>And the log if you're curious:</p>
  
  <pre><code>[14-02-26 19:56:15:980 EST] Loading URL: Work/PDF/
  [14-02-26 19:56:15:981 EST]  -&gt; Work
  [14-02-26 19:56:16:120 EST]  -&gt; PDF
  [14-02-26 19:56:16:450 EST] Loaded: null
  </code></pre>
  
  <p>And if I change getUrl to getName it (kinda) works</p>
  
  <pre><code>[14-02-26 20:10:20:588 EST] Loading URL: Work/PDF/
  [14-02-26 20:10:20:589 EST]  -&gt; Work
  [14-02-26 20:10:20:727 EST]  -&gt; PDF
  [14-02-26 20:10:21:058 EST] Loaded: Test
  </code></pre>