У меня есть два решения, которые сработали.Я опубликую оба ниже:
Вариант 1) Позволяет вам называть ссылки не именем файла:
function getFiles() {
var dApp = DriveApp;
var vfolder = dApp.getFoldersByName("video").next();
var yearfolder = vfolder.getFoldersByName("2018").next();
var gamefolder = yearfolder.getFoldersByName("game2").next();
var folderez = gamefolder.getFoldersByName("ez").next();
var foldersl = gamefolder.getFoldersByName("sl").next();
var ezIter = folderez.getFiles();
var slIter = foldersl.getFiles();
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(yearfolder+gamefolder);
var i = 2;
var files = [];
while (ezIter.hasNext()) {
files.push(ezIter.next());
}
// sorts the files array by file names alphabetically
files = files.sort(function(a, b){
var aName = a.getName().toUpperCase();
var bName = b.getName().toUpperCase();
return aName.localeCompare(bName);
});
files.forEach(function(file){
var name = file.getName();
var url = file.getUrl();
range = 'AC'+(i);
var filename = 'ezvideo'+(i-1);
var semi = ";";
var hyp = "=hyperlink(\"";
var quot = "\"";
var clos = ")";
var title = hyp + url + quot + semi + quot + filename + quot + clos; // str='=hyperlink("' + f.getUrl() + '","' + f.getName() + '")';
ss.getRange(range).setValue(title);
i++;
});
var i = 2;
var files = [];
while (slIter.hasNext()) {
files.push(slIter.next());
}
// sorts the files array by file names alphabetically
files = files.sort(function(a, b){
var aName = a.getName().toUpperCase();
var bName = b.getName().toUpperCase();
return aName.localeCompare(bName);
});
files.forEach(function(file){
var name = file.getName();
var url = file.getUrl();
range = 'AD'+(i);
var filename = 'slvideo'+(i-1);
var semi = ";";
var hyp = "=hyperlink(\"";
var quot = "\"";
var clos = ")";
var title = hyp + url + quot + semi + quot + filename + quot + clos; // str='=hyperlink("' + f.getUrl() + '","' + f.getName() + '")';
ss.getRange(range).setValue(title);
i++;
});
}
Или Вариант 2;который требует, чтобы вы использовали имена файлов для сортировки:
function getFiles() {
var dApp = DriveApp;
var vfolder = dApp.getFoldersByName("video").next();
var yearfolder = vfolder.getFoldersByName("2018").next();
var gamefolder = yearfolder.getFoldersByName("game1").next();
var folderez = gamefolder.getFoldersByName("ez").next();
var foldersl = gamefolder.getFoldersByName("sl").next();
var ezIter = folderez.getFiles();
var slIter = foldersl.getFiles();
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(yearfolder+gamefolder);
var i = 2;
while (ezIter.hasNext()) {
var file = ezIter.next();
var name = file.getName(); // use this or the created filename below
var url = file.getUrl();
range = 'AC'+(i);
var filename = 'ezvideo'+(i-1);
var semi = ";";
var hyp = "=hyperlink(\"";
var quot = "\"";
var clos = ")";
var title = hyp + url + quot + semi + quot + name + quot + clos; // str='=hyperlink("' + f.getUrl() + '","' + f.getName() + '")';
ss.getRange(range).setValue(title);
i++;
}
// START OF THE SORTING CODE-Column AC
// get the number of rows of content in Column AC
var ACvals = ss.getRange("AC2:AC").getValues();
var AClast = ACvals.filter(String).length;
// Logger.log("DEBUG: AClast = "+AClast); //DEBUG
// create a range
var range = ss.getRange(2, 29, AClast);
// Logger.log("DEBUG: range = "+range.getA1Notation());//DEBUG
// sort the range by file name
range.sort({
column: 29,
ascending: true
});
// END OF THE SORTING CODE-Column AC
i = 2;
while (slIter.hasNext()) {
var file = slIter.next();
var name = file.getName();
var url = file.getUrl();
range = 'AD'+(i);
var filename = 'slvideo'+(i-1);
var title = hyp + url + quot + semi + quot + file + quot + clos;
ss.getRange(range).setValue(title);
i++;
}
// end of the second WHILE loop.
// START OF THE SORTING CODE-Column AD
// get the number of rows of content in Column AD
var ADvals = ss.getRange("AD2:AD").getValues();
var ADlast = ADvals.filter(String).length;
// Logger.log("DEBUG: ADlast = "+ADlast); //DEBUG
// create a range
var range = ss.getRange(2, 30, ADlast);
// Logger.log("DEBUG: range = "+range.getA1Notation());//DEBUG
// sort the range by file name
range.sort({
column: 30,
ascending: true
});
// END OF THE SORTING CODE-Column AD
}
Спасибо всем за помощь !!