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

8 Answers 8

up vote 20 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
6  
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
1  
Aaaand... it's gone. Thanks, Google. –  Mastergalen Nov 9 '13 at 16:04
1  
The folder icon seems to be back now. –  Vidar S. Ramdal Mar 4 '14 at 9:56
    
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 at 14:24

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.

As of 2014-12-03, I can no longer figure out how to get from a 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.

share|improve this answer

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 '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. –  Louis Maddox Mar 11 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 –  Louis Maddox Mar 13 at 1:21

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 '14 at 21:33

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

UPDATE: Google has retired these API's so beware.

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

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

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
    
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 at 10:43
    
Yes indeed @EdRandall. I'll update this in the original - thx –  kgingeri Feb 5 at 14:41

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 http://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.
share|improve this answer
    
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. –  Al E. Jun 9 at 12:29
    
Thanks Al, I'm new to StackExchange. I removed the "above" reference and used links instead. –  Greg L. Jun 9 at 21:25

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.

share|improve this answer

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.