gdrive-copy icon indicating copy to clipboard operation
gdrive-copy copied to clipboard

Request: View folder size prior to copy and give sub folder options

Open Elliander opened this issue 7 years ago • 5 comments

Are you requesting a feature or reporting a bug?

Requesting a Feature

What is the current behavior?

If I attempt to copy a shared folder, I am unable to even see if it would exceed my available data. If I hit my limit, even after paying for more data I get this error:

Error: API call to drive.files.copy failed with error: The user has exceeded their Drive storage quota. File: application (Copy Folder). Line: 495

So I started over, but I still don't know yet if I have enough space for the rest of the files because I don't know the size of the folders or what will happen if it tries to copy a file that already exists in the destination folder. Will it skip over it and mark it as complete, or duplicate it?

What is the expected behavior?

For starters, I would like an option to scan all the files (without copying) to tell me how much storage each folder and/or sub-folder will required to be successful.

This is distinct from https://github.com/ericyd/gdrive-copy/issues/81 which would put an itemized list into a spreadsheet. What I want is to just know if it would be successful copying or not. Additionally, I would like to be able to either select a specific set of sub folders to copy, based on the information provided.

This is similar to https://github.com/ericyd/gdrive-copy/issues/69 However, rather than needing a range, I am asking to be able to select a given folders that would be able to be copied. This could, however be manually done one at a time, except I want to preserve the directory structure. Additionally, I would like for an option to ignore identical named files in the destination folder to avoid duplicating files, if this is not already a feature (I'm not sure yet).

My overall goal here is to allow me to download all of the files from a shared google drive folder with backup and sync. If I knew the size of the folders, I would be able to plan for which folders to copy and when, then I can delete the folders that were copied before setting the next folder the copy.

Specify your

  • operating system: Windows 10
  • browser: Chrome

Elliander avatar Apr 13 '19 18:04 Elliander

This is a massive feature request. It could honestly be a totally separate application. I will never have time to implement this but I'll leave it open in case someone wants to submit a PR and add this feature.

ericyd avatar Apr 13 '19 18:04 ericyd

hmm. Well, at the very least, so I can work around the issues, can you answer a question? What would happen if I start a new copy operation on a folder that already has many of the files in it?

Here's what I am thinking I can do: Delete all of the sub folders except for one, and then start a new copy operation where that one folder which remains is set as the destination folder for the new operation. So it wouldn't already have a spreadsheet inside it, but would already half a few hundred files.

Would it just continue where it left off in the old operation, or would there be duplicated files?

Also, if a given folder just has too many files, what if I pause an operation and then resume after deleting some of them. Will it ignore the files that the spreadsheet says were successfully copied, even if they are no longer in the destination folder?

If it works the way I hope, I think I can work around the limitations.

EDIT: I found a related script here: https://webapps.stackexchange.com/a/123681

Which will generate files to be placed in the top level directory that shows all of the file sizes for all the folders. Maybe something like that could be implemented?

I'm currently testing their code in a new project here: https://script.google.com/ I would still like to know the answers to the above questions, but if it works I will be able to run it before using your copy script in order to plan better.

This is their code, where running doGet() is the function to start the operation.

function doGet(){
CreateReportFile();
return ContentService.createTextOutput("Report file created in your Drive's root folder");
}

function CreateReportFile() {
  var reportContent = CreateReport();
  DriveApp.createFile('Folder Sizes Report.txt', reportContent);
}

function CreateReport(){
  var reportContent = "";
  var progressFileFound = DriveApp.getRootFolder().searchFiles("title contains 'Getting Folder Sizes,'");
  var progressFile;
  var report=[];
  if(progressFileFound.hasNext()) {
      progressFile = progressFileFound.next();
      var json = progressFile.getBlob().getDataAsString();
      try{
        report = JSON.parse(json);
      } catch(Exception) {
         DriveApp.removeFile(progressFile);
         progressFile = DriveApp.createFile("Getting Folder Sizes, 0 processed...", " ");
      }
    }
  else {
      progressFile = DriveApp.createFile("Getting Folder Sizes, 0 processed...", " ");
    }
  var f = DriveApp.getRootFolder();
  AddFolderToReport(report, f, "/", progressFile);
  DriveApp.removeFile(progressFile);
  reportContent += "TotalSize MB   FilesSize MB   Path \r\n";
  for(var i=0; i<report.length; i++)
    reportContent += Utilities.formatString("%12.2f ", (report[i].totalSize / (1024*1024))) + Utilities.formatString("%11.2f      ",(report[i].filesSize / (1024*1024))) + report[i].folderPath + "\r\n";
  return reportContent;
}

function AddFolderToReport(report, currentFolder, currentPath, progressFile){
  var report1 = [];
  for(var i=0; i<report.length; i++)
    if(report[i].folderPath == currentPath)
       return report[i].totalSize;

  var fChildren = currentFolder.getFolders();
  var totalSize = 0;
  while(fChildren.hasNext() && currentPath.length < 2000){
    var nextF = fChildren.next();
    totalSize += AddFolderToReport(report, nextF, currentPath + nextF.getName() + "/", progressFile);
  }
  var filesSize = 0;
  var files = currentFolder.getFiles();
  while(files.hasNext()){
    filesSize += files.next().getSize();
  }
  totalSize += filesSize;
  report.push({folderPath: currentPath, filesSize: filesSize, totalSize: totalSize});
  progressFile.setName("Getting Folder Sizes, " + report.length + " processed...");
  progressFile.setContent(JSON.stringify(report));
  return totalSize;
}

Elliander avatar Apr 13 '19 19:04 Elliander

The above script works! There is a limit in the operation time, so I had to start it again once to let it finish, but then it finished shortly after and gave me a report of all the file sizes in all of the folders - including the folders shared with me!

A script like that could easily be modified to only search through the source folder and sub folders being looked at, and putting the Folder Sizes Report .txt file into the destination folder as well, and generate a link to open it like your script currently does for the spreadsheet.

In my case, it looks like the folder is twice the size of what I have space for even now, but it provided me with the meaningful information I need to start over. But would it be OK for me to start over with some of the files and folders already in the destination directory, without having to worry about duplicates?

Thanks!

Elliander avatar Apr 13 '19 19:04 Elliander

I'm simply not implementing new features at this time. I can not even keep up with the bug reports, and there are feature requests literally years old (e.g. Team Drives support) that I would prioritize over this request. It's not a bad request, I just simply don't have time.

As for your questions: if you use the Resume feature, it will ignore anything that is marked as "Copied" in the spreadsheet.

If you start a fresh copy, it will copy everything. It does not matter if there are existing files in the destination folder, it will just add files to it.

I hope that helps.

ericyd avatar Apr 13 '19 19:04 ericyd

OK, understand not having time. It's why I'm looking into scripts after all ;) At least I found something that works though, and with the script posted here if the original link ever went down others searching here for a similar issue would find their solution.

It seems like I am better off just deleting everything copied and downloaded, and start over one folder at a time.

Elliander avatar Apr 13 '19 19:04 Elliander