0

So I asked for help a while back building a .xls converter, and it worked great, until now it suddenly isn't working and it's giving me this error: SyntaxError: Unexpected identifier (line 11, file "DeleteFiles"). I looked through the code and I did not spot a syntax error. Any help in solving this would be appreciated.

function XLSConvert() {

    var files = DriveApp.searchFiles("title contains '.xls' and parents in 'File_ID'");
    var destinationFolderId = "File_ID";
    var existingFileNames = getFilesInFolder(destinationFolderId);
    while (files.hasNext()) {
        var xFile = files.next();
        var name = xFile.getName();
        try {
            if (!existingFileNames[name] && (name.indexOf('.xls') > -1)) {
                var ID = xFile.getId();
                var xBlob = xFile.getBlob();
                var newFile = {
                    title: name,
                    key: ID,
                    'parents': [{
                        "id": destinationFolderId
                    }]
                }
                file = Drive.Files.insert(newFile, xBlob, {
                    convert: true
                });
            }
        } catch (error) {
            console.error("Error with file " + name + ": " + error);
        }
    }

    function getFilesInFolder(folderId) {
        var folderId = "File_ID";
        var folder = DriveApp.getFolderById(folderId);
        var filesIterator = folder.getFiles();
        var files = {};
        while (filesIterator.hasNext()) {
            var file = filesIterator.next();
            files[file.getName()] = true;
        }
        return files;
    }

}
5
  • Have you enabled the 'Drive ApI'? Commented Feb 7, 2020 at 19:48
  • Yes I have it enabled V2 Commented Feb 7, 2020 at 19:55
  • Which line is line 11? Commented Feb 7, 2020 at 19:56
  • 1
    I figured it out! It's because Google just implemented the switch over from Rhino runtime to V8. So the old nomenclature is causing the problem. I just switched it over to run the legacy for right now. I'll have to see how to change it properly to allow it to use the V8 >< Commented Feb 7, 2020 at 20:02
  • 1
    For the benefit of future users could you provide a more detailed answer to the problem. Thanks. Commented Feb 7, 2020 at 20:11

1 Answer 1

2

If you encounter this problem, specifically pertaining to a syntax error that you never had before on a certain script, it may be that Google's switch over from Mozilla Rhino (ES5) to Chrome V8 has caused previous syntax that worked fine to be problematic. If you want to still run the scripts without changing them to fit the newer nomenclature, just go to "Run" and Select "Run in Legacy Mode" on the bottom of the menu.

How to migrate your scripts to function under Chrome V8: https://developers.google.com/apps-script/guides/v8-runtime/migration

How to enable legacy mode to allow your scripts to continue running under Rhino: https://developers.google.com/apps-script/guides/v8-runtime#enabling_the_rhino_runtime

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.