I'm trying to select a few csv files that are in my Google drive and convert them to Google Sheets files. I know that I can do this one by one using the Open option, but since I have hundreds of files, I'm looking for a way to do this using multi-select and convert.
Asked
Active
Viewed 7,695 times
1 Answers
12
I know two ways to convert multiple files, and "multi-select and convert" is not one of them.
Reupload
Download the files, then upload again, having first enabled "convert uploads" in Drive settings.
Script
Using an Apps Script, one can convert CSV files to Google Spreadsheet format automatically. First, move the files to be converted to a folder and take a note of its id (the part of the shareable link after ?id=
). Use the folder id in the following script.
function convert() {
var folder = DriveApp.getFolderById('folder id here');
var files = folder.getFiles();
while (files.hasNext()) {
var file = files.next();
Drive.Files.copy({}, file.getId(), {convert: true});
}
}
Follow the instructions to enable Advanced Drive Service, which is used by the script. Finally, run it. It will create converted copies of all files in the given folder.
-
Awesome @Bookend. The script worked like a charm! Just to add a bit to the scenario, my files are copied to Google Drive automatically and updated by a script for 24 hours, hence I couldn't use the convert=true at the time of uploading. – kkotak Jul 02 '16 at 18:53
-
BTW, Would you have any pointers on copying files to another folder and running this script at midnight automatically? Thanks again for your prompt and concise response. – kkotak Jul 02 '16 at 19:00
-
1Use a [timed trigger](https://developers.google.com/apps-script/guides/triggers/installable#managing_triggers_manually) to run a function every 24 hours. For simply copying files there's [makeCopy](https://developers.google.com/apps-script/reference/drive/file#makecopydestination) in the standard [DriveApp service](https://developers.google.com/apps-script/reference/drive/drive-app). But if you know which files are to be converted, then you don't need to move them to a folder; just loop through the files and convert. One option is to `DriveApp.search` to locate the files. – Jul 03 '16 at 04:08