Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

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?

share|improve this question
add comment

6 Answers

up vote 7 down vote accepted

A document can potentially be in multiple folders, but you can get a list of them through the UI.

  1. First, click the folder icon next to the document title: folder icon
  2. This will open a list of the folders that the current document is in:
    folder list
  3. You can click the folder name from that list to go to the main Drive listing for that folder, or click the Organize button to move the document to another folder.
share|improve this answer
4  
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
    
Aaaand... it's gone. Thanks, Google. –  mastergalen Nov 9 '13 at 16:04
    
The folder icon seems to be back now. –  Vidar S. Ramdal Mar 4 at 9:56
add comment

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.

share|improve this answer
    
A round about way but it's a solution. Thanks! –  Claus May 6 '13 at 19:32
    
Only useful if your parent folder name is unique. Not always the case... –  Fuhrmanator Mar 23 at 21:33
add comment

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.

share|improve this answer
add comment

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);
}
share|improve this answer
    
What if my document is a PowerPoint (non Google apps) file on google drive? –  Fuhrmanator Mar 23 at 21:33
add comment

I realized this has already been answered, but just in case people find it while searching (I did) I'll add some to it. 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
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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