0

I found a script that will automatically add the file name to the description of all of my files in Google Drive but when I run the script I get the error that DocsList is not defined. I'm new to writing scripts and I've been searching the Google Scripts site but I'm still lost. I'd really appreciate any help that you can offer. Thank you!

function setDescriptionToFolderNames() {

    var file;
    var filename;
    var folders;
    var filedescription;

    var contents = DocsList.getAllFiles();
    // sort ascending. Oldest first, in case of timeout:
    contents.sort(function(a,b) {return a.getLastUpdated()-b.getLastUpdated()});

    // synchronize folder names of all files (only updates if folders have changed):
    for (var i = 0; i < contents.length; i++) {
    file = contents[i];
    try {
    filename = file.getName();
    //Logger.log("Checking: " +filename +" ("+file.getLastUpdated()+")");
    folders = file.getParents();

    // sort by folder name:
    folders.sort(function(a, b) 
                 { return a.getName().localeCompare(b.getName()); }
                );
    filedescription = "";

    for (var f = 0; f < folders.length; f++) {
      filedescription = filedescription+folders[f].getName()+" ";
    }

    if (filedescription != contents[i].getDescription())
    { 
      file.setDescription(filedescription);
      Logger.log("Updated: " +filename);
    }
 } catch(e){ Logger.log("Error: " +filename+" "+e); }
 }

 };
Lauren
  • 1

1 Answers1

0

Based from this forum, DocsList is deprecated and use DriveApp instead. Class DriveApp allows scripts to create, find, and modify files and folders in Google Drive.

// Log the name of every file in the user's Drive.
 var files = DriveApp.getFiles();
 while (files.hasNext()) {
   var file = files.next();
   Logger.log(file.getName());
 }

Hope this helps!

abielita
  • 13,147
  • 2
  • 17
  • 59
  • I know this is old but I just had to sort this out for myself including getting tagging done on google drive and I came accross the same script, just like the OP. Finally I found this, which is an updated version of the same script and will answer the question well and also show you how to update the functions used in the script of the OP. http://www.chew.ch/leonard/software/googleScripts/setDescriptionToFolderNames.txt – Dom Feb 19 '19 at 20:52