132

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?

12 Answers 12

105

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:

enter image description here

If the document is in more than one folder, you get a list of the folders it is in with hyperlinks to each.

Screenshot of two parent folders

17
  • 19
    I remember this "folder icon" being there a while back, but it is gone now. Anyone know how to find the parent folder in the new design?
    – Mike Eng
    Oct 24 '13 at 18:20
  • 5
    The "This item is in:" text has now moved to the dialog that appears after you click on the "folder icon". Unfortunateyl, this doesn't appear to work for files you haven't created.
    – Jedidja
    May 4 '15 at 14:24
  • 24
    Google Drive's UI is such a mess… Oct 13 '15 at 1:39
  • 3
    @Jangari Yes, as nonsensical as it is, you get hyperlinks if the document is in multiple folders, but no hyperlink if the document is only in one folder. I'd encourage you to submit this product feedback to Google. Maybe they will change it if they get enough feedback of the sort. google.com/tools/feedback/intl/en
    – Mike Eng
    Jun 26 '17 at 15:55
  • 5
    The folder icon is only visible if you have permission to move the file.
    – hultqvist
    Dec 3 '19 at 10:15
22

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.:

When the little folder icon is missing...

And you'll find where the hell Waldo is. I found myself in world-2!

2
  • 3
    This method shows location name only, without the URL to the folder.
    – Kos
    May 1 '20 at 23:31
  • Alas, this seems to be broken, as well. I just opened that menu item and all I see for the document I had open was Location -. Jul 27 at 3:01
14

Update: Folder icon has now changed to a move icon, but it still works...

enter image description here

4
  • 1
    It is the same as accepted answer
    – Kos
    May 1 '20 at 12:49
  • 2
    Well, the folder-icon changed and I got temporarily confused so I thought I should post it "why not"... It is a bit strange to access the function "Open document location" from the "Move file" menu... May 1 '20 at 22:28
  • 2
    I see, so then it should be just an edit to the existing answer.
    – Kos
    May 1 '20 at 23:36
  • 1
    +1 This is a useful addition, since it's terribly unintuitive that one should click a "move" icon to reveal another icon with no obvious meaning which then opens another tab which shows the location of the folder that holds the current document. (And why "file > document details" merely shows the folder name (not path) with no such link is beyond comprehension.)
    – michael
    Feb 11 at 7:32
9

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.

2
  • This no longer works. Jul 27 at 3:02
  • It works for me, for files in My Drive and Shared Drives where I have access. It does not work for files Shared with Me that I haven't added to a folder. Aug 12 at 10:38
5

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);
}
5
  • What if my document is a PowerPoint (non Google apps) file on google drive? Mar 23 '14 at 21:33
  • @Fuhrmanator access it with DriveApp API not DocumentApp, each file has a mimetype (filetype) in Drive you can find it on as well as a unique file ID. Mar 11 '15 at 14:20
  • Specifically, for a folder of known id id, set source_folder = DriveApp.getFolderById(id), and use source_folder.getFilesByType(MimeType.MICROSOFT_POWERPOINT) or ...MimeType.MICROSOFT_POWERPOINT_LEGACY (or you can use the actual mime type string the latter part evaluates to). See docs here Mar 13 '15 at 1:21
  • 1
    If someone can show how do do this for all documents (without having to add in manually to each, then it would be useful). May 12 '20 at 18:16
  • I've updated this so it works after some of the APIs have been discontinued. However, this really shouldn't be needed given the accepted answer.
    – sferencik
    Apr 12 at 6:05
1

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.

3
  • A round about way but it's a solution. Thanks!
    – Claus
    May 6 '13 at 19:32
  • 1
    Only useful if your parent folder name is unique. Not always the case... Mar 23 '14 at 21:33
  • @Fuhrmanator it is still useful if the parent folder name is not unique, you just need to search through all the folders (which may be difficult if the # of folders is large, but still).
    – ThomasW
    Dec 25 '17 at 2:47
1

Parent folder

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;
}

It looks like this

enter image description here

To install

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

Note

Only the parent folder is mentioned (exactly what you wanted) but it will not disclose the full path.

1

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:

Find parent folder UI

To install:

  1. goto script.google.com, while logged in
  2. start a new script
  3. paste code and press the bug icon. Press authorize.
  4. under file>menaged version save the script.
  5. goto Publish>Deploy as web app and press update
  6. the url presented (exec at the end) will allow you to run the stand-a-lone script.
2
  • 2
    Just a note: "above" doesn't really have any context in answers, since answers can be sorted in different ways. Better to link to the answers to which you are referring.
    – ale
    Jun 9 '15 at 12:29
  • Thanks Al, I'm new to StackExchange. I removed the "above" reference and used links instead.
    – Greg L.
    Jun 9 '15 at 21:25
1

UPDATE: Google has retired these APIs so beware.

NOTE: this really is no longer needed using the new drive UI.

  1. when you search or have any document list, hi-light the file you wish to find
  2. click the [i] (info) button in the upper right
  3. click in "Details" (vs default "Activity")
  4. you will see sharing and where it is stored etc

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: Script UI

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
2
  • Exactly what I need; sadly Google deprecated UiApp on 11th Dec 2014 so this will need re-writing at some point. That's the trouble with cloud services, nothing works for long, you're at their mercy.
    – Ed Randall
    Feb 4 '15 at 10:43
  • Yes indeed @EdRandall. I'll update this in the original - thx
    – kgingeri
    Feb 5 '15 at 14:41
1

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.

File location (view only permission)

Search for the file title in Drive

Search Query: title:Contributor

Shortcut locations (no previous shortcuts)

When there's no previous shortcuts the folder icon is missing.

Missing Folder icon. Add a shortcut to drive

Shortcut locations (with existing shortcuts)

Add another shortcut

File location (edit permission)

When you have edit permissions the UI is slightly different.

Move file dialog

Shortcuts

The menu looks different whether there exist previous shortcuts or not. This is important when guiding someone that they might see any of these.

Without and with previous shortcuts

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.

Shortcuts dialog

0

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.

2
  • This looks like it will only work if the file name is unique. May 12 '20 at 18:24
  • Yes this is the only user accessible solution when you don't have Edit permission to the file.
    – hultqvist
    Apr 18 at 19:21
0

As of April 2020, to find the location of your document:

  1. copy your document file name
  2. search for the file in Google Drive
  3. select it in the search result
  4. open the information panel on the right (View Details)
  5. there you can find the clickable folder where the file is located, next to Location.
1
  • This looks like it will only work if the file name is unique. May 12 '20 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.