Often I have the direct link to a Google Document (mine or an organizational shared one) and want to find documents that are stored within the same folder. To do so, I would need to determine the folder the document is in.
Is there a way to do that?
Often I have the direct link to a Google Document (mine or an organizational shared one) and want to find documents that are stored within the same folder. To do so, I would need to determine the folder the document is in.
Is there a way to do that?
A document can potentially be in multiple folders, but you can get a list of them through the UI.
Click the folder icon next to the document title. If the document is in a single folder, you get a view into that single folder showing the folder name with an icon to open the folder in a new tab, other documents in the folder, and options to move the current document:
If the document is in more than one folder, you get a list of the folders it is in with hyperlinks to each.
Missing the Folder Icon?
If you find that little folder missing to the right of the file name, then you can choose File > Document details... to at least see the parent directory name. E.g.:
As of 2014-04-04, there are a couple of ways to get from a document to its containing folder.
From the open document, click the folder icon next to the document's title. A dialog appears with "This item is in" and the containing folder name. The folder name is linked to the folder. If a "Move to" dialog appears instead, the document's containing folder is the root. If it's your document or you've explicitly added it, it's in My Drive. If not, try More -> All Items in the folder list at the left of the document list view.
From the document search view, select the item. More -> Details and activity -> Details -> Folders. Any folder names listed are linked to the corresponding folders.
As of 2014-12-03, I can no longer figure out how to get from a file view to its containing folder, for files that are not collaborative Google documents. Please comment or edit this answer if you know how.
Google is moving away from their previous model where files and folders could have multiple parents. When they introduced Shared Drives for teams there could only be one parent and My Drive is migrating no longer allowing new parents to be added.
The UI has since then been updated to work with Shortcuts instead of multiple parents.
Below I will show how to access both the file location and all shortcut locations.
The UI is different whether you have edit permission or not to the file.
Search for the file title in Drive
When there's no previous shortcuts the folder icon is missing.
When you have edit permissions the UI is slightly different.
The menu looks different whether there exist previous shortcuts or not. This is important when guiding someone that they might see any of these.
Although the dialog showing the shortcut looks like it's coming from the Folder icon, you can't open it by clicking the icon, you must open it from the File menu as seen above.
Let's provide a means to go to the document's parent folder with a click of the mouse.
Place the script below in your document's 'container-bound' script editor. Do this by opening your document and then from the document menu bar, select Tools > Script editor...
If this is your first time editing that document's script, default code will populate the editor's screen. Simply replace the script content with the code below. Include both the function onOpen() and listParentFolders() listed below.
Save the script in the editor and then 'refresh' the browse window displaying the associated document. A new menu item will appear for the document named Utils. Clicking on the Utils Menu pad will display the menu popup, Show Path. This script will display the directory path as a list of hyperlinks.
function onOpen() {
// Add a menu with some items, some separators, and a sub-menu.
DocumentApp.getUi().createMenu('Utils')
.addItem('Show Path', 'listParentFolders')
.addToUi();
}
function listParentFolders() {
var theDocument = DocumentApp.getActiveDocument();
var docID = theDocument.getId();
var theFile = DocsList.getFileById(docID);
var parents = theFile.getParents();
// No folders
if ( parents == null ) return;
var folder = parents[0];
var folderName = folder.getName();
var folderURL = folder.getUrl();
var folders = [[folderName,folderURL]];
while (folderName != "Root"){
parents = folder.getParents();
folder = parents[0];
folderName = folder.getName();
folderURL = folder.getUrl();
folders.unshift([folderName,folderURL]);
}
var app = UiApp.createApplication().setTitle("Folder Hierarchy").setHeight(250).setWidth(300);
var grid = app.createGrid(folders.length, 1).setStyleAttribute(0, 0, "width", "300px").setCellPadding(5);
var indentNum = 0, link;
for (var fldCntr = 0; fldCntr < folders.length; fldCntr++){
folderName = folders[fldCntr][0];
folderURL = folders[fldCntr][1];
link = app.createAnchor(folderName, folderURL).setId("id_" + fldCntr).setStyleAttribute("font-size", "10px");
grid.setWidget(indentNum, 0, link);
indentNum += 1;
}
app.add(grid);
DocumentApp.getUi().showSidebar(app);
}
AFAIK no, there is no way to do this from the document URL or the document itself. You'd need to grab the title of the doc and search for it in your Drive list view. The search results should show you the document title, then also show the name of the parent folder in gray.
I wrote a little script that retrieves the parent folder, based on the key of the document:
function doGet() {
// create app and grid
var app = UiApp.createApplication();
var grid = app.createGrid(4,2);
// set labels for first column
grid.setWidget(0, 0, app.createLabel("Add document key: ")
.setStyleAttribute('fontWeight', 'bold'));
grid.setWidget(2, 0, app.createLabel("Parent Folder: ")
.setStyleAttribute('fontWeight', 'bold'));
// set text boxes for second column
grid.setWidget(0, 1, app.createTextBox().setId("key")
.setName("key").setWidth(500));
grid.setWidget(2, 1, app.createTextBox().setId("path")
.setName("path").setWidth(500));
// create button and handler
grid.setWidget(3, 0, app.createButton("PATH")
.addClickHandler(app.createServerHandler("getPath")
.addCallbackElement(grid)));
// add grid to application and show app
app.add(grid);
return app;
}
function getPath(e) {
// get active application and key
var app = UiApp.getActiveApplication();
var key = e.parameter.key;
// Get file and path
var path;
try {
var file = DocsList.getFileById(key);
path = file.getParents()[0].getName();
} catch(e) {
path = "file not found";
}
// add path to application and update app
app.getElementById("path").setValue(path);
return app;
}

file>menaged version save the script. Publish>Deploy as web app and press updateOnly the parent folder is mentioned (exactly what you wanted) but it will not disclose the full path.
UPDATE: Google has retired these APIs so beware.
NOTE: this really is no longer needed using the new drive UI.
I realized this has has already been answered, but just in case people find it while searching (as I did), I'll add some more information. If you are new to Google App Script see this link.
Thanks to @Jacob Jan Tuinstra and @Drawn for their scripts, but neither was quite what I needed, so I used both of theirs to create mine. The script below needs to be pasted into a GApps script editor, then published as a web app. The link should be saved/bookmarked for later re-use:
function doGet() {
// create app and grid
var app = UiApp.createApplication();
var grid = app.createGrid(4,2);
// set labels for first column
grid.setWidget(1, 0, app.createLabel("Document's key: ")
.setStyleAttribute('fontWeight', 'bold'));
grid.setWidget(2, 0, app.createLabel("Folder Path: ")
.setStyleAttribute('fontWeight', 'bold'));
// set text boxes for second column
grid.setWidget(1, 1, app.createTextBox().setId("key")
.setName("key").setWidth(500));
grid.setWidget(2, 1, app.createTextBox().setId("path")
.setName("path").setWidth(500));
// create button and handler
grid.setWidget(3, 0, app.createButton("Find")
.addClickHandler(app.createServerHandler("listParentFolders")
.addCallbackElement(grid)));
// add grid to application and show app
app.add(grid);
return app;
}
function listParentFolders(e) {
var app = UiApp.createApplication();
var path = '';
var key = e.parameter.key;
var theFile = DocsList.getFileById(key);
var parents = theFile.getParents();
// No folders
if ( parents == null ) {
app.getElementById("path").setValue('unknown');
return app;
}
var folder = parents[0];
var folderName = folder.getName();
var folders = [[folderName]];
try {
folderName = parents[0].getName();
}
catch(error)
{
app.getElementById("path").setValue('(unknown - shared document)');
return app;
}
while (folderName != "Root"){
parents = folder.getParents();
folder = parents[0];
folderName = folder.getName();
// we are going in reverse - build list in other direction
folders.unshift([folderName]);
}
// built path list
var indentNum = 0;
for (var fldrCntr = 0; fldrCntr < folders.length; fldrCntr++){
folderName = folders[fldrCntr][0];
if(fldrCntr == 0) {
path = 'My Drive'; // ...instead of 'Root'
} else {
path += ' / ' + folderName;
}
indentNum += 1;
}
app.getElementById("path").setValue(path);
return app;
}
The UI looks like this:

Note that a file's ID comes from it's URL - i.e. see "<...>" in URL sample below:
https://docs.google.com/a/your_domain/spreadsheet/ccc?key=<...>&usp=drive_web#gid=0
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:
As of April 2020, to find the location of your document:
For anyone else that comes across this, below are the instructions as of May 8th 2024:
This took me one hour to figure out. Please upvote so that others don't waste the same amount of time.
Google has already provided a solution to that:
Let's suppose you looking for a pdf document called myreport.pdf.
You search for myreport, you get a list of documents that satisfy the criteria.
If you want to know the folder it is in, just Right Click and Click on Locate in My Drive.