-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFileFromFolder.gs
More file actions
37 lines (33 loc) · 977 Bytes
/
getFileFromFolder.gs
File metadata and controls
37 lines (33 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function getFilefromFolder(folderName,fileName)
{
var results = null;
// Get all folders with this name
var fldr = DriveApp.getFoldersByName(folderName);
// Check that at least one directory was returned
if (fldr.hasNext() === false)
{
Logger.log('getFilefromFolder - No directories found for the specified name');
}
else
{
// Go through the returned folders
while (fldr.hasNext())
{
// Get all files with this name
var allFilesInFolder = fldr.next().getFilesByName(fileName);
// Check that at least one file was returned
if (allFilesInFolder.hasNext() === false)
{
Logger.log('getFilefromFolder - No files with the provided name found inside the specified directory');
}
else
{
var targetFile = allFilesInFolder;
results = targetFile;
}
// *Only* the first directory returned is examined
break;
}
}
return results;
}