Custom javascript
- or -
Post a project like this3506
£30(approx. $38)
- Posted:
- Proposals: 0
- On-site in London, GB
- #555054
- Awarded
Description
Experience Level: Intermediate
customise JavaScript to return absolute files rather than file from gdrive.
function below returns urls from a gdrive spreadsheet however wish to return files from absolute address ie. without the drive app root folder included.
//This function gets the file from GDrive
function getFile(loc) {
var locArray = loc.split('/');
Logger.log(locArray);
var folder = getFolder(loc);
if(folder.getFilesByName(locArray[locArray.length-1]).hasNext()) {
return folder.getFilesByName(locArray[locArray.length-1]).next();
} else {
return null;
}
}
//This function finds the folder for the file and creates folders if needed
function getFolder(folderPath) {
var folder = DriveApp.getRootFolder();
if(folderPath) {
var pathArray = folderPath.split('/');
for(var i in pathArray) {
if(i == pathArray.length - 1) { break; }
var folderName = pathArray[i];
if(folder.getFoldersByName(folderName).hasNext()) {
folder = folder.getFoldersByName(folderName).next();
}
}
}
return folder;
}
function below returns urls from a gdrive spreadsheet however wish to return files from absolute address ie. without the drive app root folder included.
//This function gets the file from GDrive
function getFile(loc) {
var locArray = loc.split('/');
Logger.log(locArray);
var folder = getFolder(loc);
if(folder.getFilesByName(locArray[locArray.length-1]).hasNext()) {
return folder.getFilesByName(locArray[locArray.length-1]).next();
} else {
return null;
}
}
//This function finds the folder for the file and creates folders if needed
function getFolder(folderPath) {
var folder = DriveApp.getRootFolder();
if(folderPath) {
var pathArray = folderPath.split('/');
for(var i in pathArray) {
if(i == pathArray.length - 1) { break; }
var folderName = pathArray[i];
if(folder.getFoldersByName(folderName).hasNext()) {
folder = folder.getFoldersByName(folderName).next();
}
}
}
return folder;
}
Dan P.
100% (37)Projects Completed
31
Freelancers worked with
26
Projects awarded
31%
Last project
11 Aug 2021
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies