1
votes

Anybody knows a formula to extract the file name of a Google Drive URL on a Google Spreadsheet?

The GDrive link is on the Column A and I want to have the file name of that link on Column B.

1
You can't really extract it, since the file name is not in the drive URL.JPV

1 Answers

1
votes

Just to illustrate: this should get the file names of the drive URL's in col A, if that drive URL is a spreadsheet. You will have to find a way to extend the functionality to also get the names of non-spreadsheet file (maybe use .getFileType() to do that).

function getFileNames() {
var names = [];
var ss = SpreadsheetApp.getActive()
    .getSheets()[0];
var val = ss.getRange(2, 1, ss.getLastRow(), 1)
    .getValues();
for (var i = 0, lenr = val.length; i < lenr; i++) {
    for (var j = 0, lenc = val[0].length; j < lenc; j++) {
        if (val[i][j]) {
            names.push([SpreadsheetApp.openByUrl(val[i][j])
            .getName()])
        }
    }
}
ss.getRange(2, 2, names.length, names[0].length)
    .setValues(names);
}