-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchFilesInFolder.gs
More file actions
38 lines (34 loc) · 1.09 KB
/
searchFilesInFolder.gs
File metadata and controls
38 lines (34 loc) · 1.09 KB
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
37
38
// This function will search files in folders by a specific pattern. Keep in mind that if more than one folder with the same name exists, only the first one with be searched
function searchFilesInFolder(folderName,fileName)
{
var allFilesInFolder
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('searchFilesInFolder - No directories found for the specified name');
}
else
{
// Go through the returned folders
while (fldr.hasNext())
{
// Get all files with this name
allFilesInFolder = fldr.next().searchFiles(fileName);
// Check that at least one file was returned
if (allFilesInFolder.hasNext() === false)
{
Logger.log('searchFilesInFolder - No files with the provided name found inside the specified directory');
}
else
{
var targetFile = allFilesInFolder;
results = targetFile;
}
break;
}
}
return results;
}