Converting all Google Drive files to Google Drive Format.

1,227 views
Skip to first unread message

Adrian Dunne

unread,
Aug 22, 2016, 9:49:46 PM8/22/16
to Google Apps Manager
Hello,

I recently did a massive upload of data (several Terabytes) from local hard drives into Google Drive, but I forgot to select the option to convert the files to Google Drive format. Now I have all these files in G Drive but they are all still in their native format. 

Does anyone know if its possible to select all of my Google Drive content and convert everything over to Googles Drives format. I spoke with Google Support and they don't have this option available. They don't even have an option for Selecting All the contents of your Drive at once (unless you are doing an Export. 

Thanks for any help. 

Julien POIROT

unread,
Aug 23, 2016, 6:27:05 AM8/23/16
to Google Apps Manager
Hi
You won't be able to do this with GAM, but it is possible using Advanced Drive Service in Google Apps Script :  https://developers.google.com/apps-script/advanced/drive
You have to use an iterator for all files matching your criteria and then use the following function (example from this thread - xlsx content :  https://code.google.com/p/google-apps-script-issues/issues/detail?id=1019 ) and add a "delete once converted" step


function convert() {
  var folderIncoming = DocsList.getFolder('Incoming RFQs');
  var folderXLSX = DocsList.getFolder('XLSX');
  
  var files = folderIncoming.getFiles();
  
  for (var i in files) {  
    var xlsxBlob = files[i];
  
    var fileName = xlsxBlob.getName();
    
    var file = {
      title: fileName,
      "parents": [{
        "kind": "drive#parentReference",
        "id": "XYZ123"
      }]
    };
    
    file = Drive.Files.insert(file, xlsxBlob, {
      convert: true
    });
    
    files[i].addToFolder(folderXLSX);   
    files[i].removeFromFolder(folderIncoming);    
  }
}

Regards

Julien

Adrian Dunne

unread,
Aug 24, 2016, 6:32:54 PM8/24/16
to Google Apps Manager
Thanks Julien. I will check this out. Much appreciated. 

Rob Martin

unread,
Jul 28, 2017, 7:56:06 AM7/28/17
to GAM for G Suite
Adrian 

I have the same issue and would welcome some advice on how you solved this problem.

Thanks

Rob 
function convert() {
  var folderIncoming = DocsList.getFolder('Incoming RFQs');
  var folderXLSX = DocsList.getFolder('XLSX');
  
  var files = folderIncoming.getFiles();
  
  for (var i in files) {  
    var xlsxBlob = files[i];
  
    var fileName = xlsxBlob.getName();
    
    var file = {
      title: fileName,
      "parents": [{
        "kind": "drive#parentReference",
        "id": "XYZ123"
      }]
    };
    
    file = Drive.Files.insert(file, xlsxBlob, {
      convert: true
    });
    
    files[i].addToFolder(folderXLSX);   
    files[i].removeFromFolder(folderIncoming);    
  }
}

Regards

Julien

Le mardi 23 août 2016 02:49:46 UTC+1, Adrian Dunne a écrit :
Hello,

I recently did a massive upload of data (several Terabytes) from local hard drives into Google Drive, but I forgot to select the option to convert the files to Google Drive format. Now I have all these files in G Drive but they are all still in their native format. 

Does anyone know if its possible to select all of my Google Drive content and convert everything over to Googles Drives format. I spoke with Google Support and they don't have this option available. They don't even have an option for Selecting All the contents of your Drive at once (unless you are doing an Export. 

Thanks for any help. 

http://www.datacable.co.uk/home/images/Email/tree.jpg Please consider the environment before printing this e-mail!

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 

Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. 
Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. 
If you have received this e-mail in error please notify sup...@datacable.co.uk or telephone 01535 616000 and delete it from your system.

Alex Singleton

unread,
Jul 28, 2017, 4:46:29 PM7/28/17
to GAM for G Suite
Hey Rob, 

I've been trying to figure this out too. Unfortunately, documentation and examples in "Google Drive Script" are rare, but below is my implementation that replaces the deprecated methods in Julien's example. 

It work up to the last line, where I get the following message on the call to add the file to the folder: Cannot convert [object Object] to File. (line 35).

If we can figure out what causes the file variable to be recognized as an object instead of google doc, we could be in business. 

function convert() {
  
 var targetFolder_1 = DriveApp.getFoldersByName('ProvaSport'); 
 var targetFolder =  targetFolder_1.next();                                                // getFoldersByName returns an iterator, use .next() to get Folder
 var folderGoogify_1 = DriveApp.getFoldersByName('TransferTest');
 var folderGoogify = folderGoogify_1.next();  
 var counter = 0; 
  
 var files = targetFolder.getFiles(); 
 var folderID = targetFolder.getId();
   
 while (files.hasNext()) {

   var nextFile = files.next();
   var blob = nextFile.getBlob();
   var fileName = nextFile.getName();
   //var kind = nextFile.getParents();
   //var id = nextBlob.getId();
       
    var file = {
      title: fileName,
      //mimeType: "application/vnd.google-apps.document",
      "parents": [{
        "kind": "drive#parentReference",
        "id": folderID
      }]
    };

      file = Drive.Files.insert(file, blob, {
      convert: true
       });
          
     counter++;
     folderGoogify.addFile(file);
   //targetFolder.removeFromFolder();  
   
 }
}

J D

unread,
Mar 20, 2018, 10:07:20 AM3/20/18
to GAM for G Suite
Hi all,

I realise that this is an old thread, so this isn't of much use to anyone who has already faced this issue - but to anyone who comes across this in the future and has the same issue (e.g. uploaded files without converting them, or used a command line tool to upload that doesn't support conversions)....

I did the same thing (intentionally :) ) during a large (multi-gigabyte) migration project. I wrote a web-app to do the conversion for me, as I also needed to keep copies of the unconverted files as well (in Google Drive). 

It's online and free to use:


And there are instructions here:


Anyway, it might be useful for people who are in the same situation! Hope so.

Thanks,

JD.

JA

unread,
Jan 31, 2019, 10:19:16 PM1/31/19
to GAM for G Suite
Hi JD - Just used this for my problem --- organizing years' worth of multiple team members doing their own thing and uploading whatever they wanted, in whatever formats they wanted --- a total mess.  Tried running some of the sample scripts above and in other posts with no luck.  Not tech savvy enough?  But your solution has worked for my purposes.  Thank you very much.  ~JA

J D

unread,
Feb 1, 2019, 3:37:49 AM2/1/19
to GAM for G Suite
Hi,

It's a pleasure! Glad it solved your problem :)

JD

+KimNilsson

unread,
Feb 7, 2019, 8:33:24 AM2/7/19
to GAM for G Suite
J D,

I posted a link to your tool to the GSFE Admins community on Google+ (yes, it still alive, and will stay so).
Much appreciated that you told us about it.
Reply all
Reply to author
Forward
0 new messages