Here is a more complete and reliable implementation of the two scripts in these answers (first one and second one) to this question. This script allows you to paste the full URL of the file or the file ID into the first edit box in the dialog and then returns a text representation of the path as well as a link to the parent directory. The installation instructions are identical to what is shown above by Jacob, I copied them below for completeness.
NOTE: Some of the APIs used in all of these scripts are now obsolete. They are still working as of when this post was made, but will probably stop working in the future.
//
// Take a Google Drive file URL or ID and output a string representation of the path as well as a link
// to the parent folder
//
// Based on https://webapps.stackexchange.com/questions/43881/how-to-view-the-parent-folder-of-a-google-document
function doGet() {
// create app and grid
var app = UiApp.createApplication();
var grid = app.createGrid(5,2);
// set labels for first column
grid.setWidget(1, 0, app.createLabel("URL or file ID: ").setStyleAttribute('fontWeight', 'bold'));
grid.setWidget(2, 0, app.createLabel("Folder Path: ").setStyleAttribute('fontWeight', 'bold'));
grid.setWidget(3, 0, app.createLabel("Folder URL: ").setStyleAttribute('fontWeight', 'bold'));
// set text boxes for second column
grid.setWidget(1, 1, app.createTextBox().setId("key").setName("key").setWidth(1000));
grid.setWidget(2, 1, app.createTextBox().setId("path").setName("path").setWidth(1000));
grid.setWidget(3, 1, app.createAnchor("","").setId("url").setName("url").setWidth(1000));
// create button and handler
grid.setWidget(4, 0, app.createSubmitButton("Find")
.addClickHandler(app.createServerHandler("listParentFolders")
.addCallbackElement(grid)));
// add grid to application and show app
app.add(grid);
return app;
}
//
// getIdFromUrl - Get the file id portion of the url. If the file id itself is passed in it will match as well
//
// From http://stackoverflow.com/questions/16840038/easiest-way-to-get-file-id-from-url-on-google-apps-script
// This regex works for any google url I've tried: Drive url for folders and files, Fusion Tables, Spreadsheets,
// Docs, Presentations, etc. It just looks for anything in a string that "looks like" a Google key. That is, any
// big enough string that has only (google key) valid characters in it.
//
// Also, it works even if it receives the ID directly, instead of the URL. Which is useful when you're asking
// the link from the user, as some may paste the id directly instead of the url and it still works.
function getIdFromUrl(url) {
return url.match(/[-\w]{25,}/);
}
function listParentFolders(e) {
var app = UiApp.createApplication();
var key = getIdFromUrl(e.parameter.key);
var theFile = DriveApp.getFileById(key);
var parents = theFile.getParents();
var fileName = theFile.getName();
// no folders
if ( parents == null ) {
app.getElementById("path").setValue('Unknown file');
return app;
}
var url;
var folder;
var folderName;
var path;
// traverse the list of parents of folders to build the path
while (parents.hasNext()){
folder = parents.next();
folderName = folder.getName();
// on the first pass get the URL of the folder which is the parent folder of the file
if (url == null)
url = folder.getUrl();
// build up a string version of the path
if (path == null)
path = folderName;
else
path = folderName + ' / ' + path;
// get the parent of the current folder
parents = folder.getParents();
}
app.getElementById("path").setValue(path);
app.getElementById("url").setHref(url).setText(url);
return app;
}
It looks like this:

To install:
- goto script.google.com, while logged in
- start a new script
- paste code and press the bug icon. Press authorize.
- under file>menaged version save the script.
- goto Publish>Deploy as web app and press update
- the url presented (exec at the end) will allow you to run the stand-a-lone script.