-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.gs
32 lines (26 loc) · 1.01 KB
/
script.gs
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
function log() {
var folderName = "name of google drive folder goes here";
var folderListing = "name of spreadsheet";
var folders = DriveApp.getFoldersByName(folderName);
var folder = folders.next();
var contents = folder.getFiles();
var spreadsheet = SpreadsheetApp.create(folderListing);
var sheet = spreadsheet.getActiveSheet();
sheet.appendRow(['ITEM', 'CATEGORY', 'QUANTITY']);
var file;
var fileName;
var link;
while(contents.hasNext()) {
var info = [{}];
file = contents.next();
link = file.getUrl();
fileName = file.getName(); // file names are written in format as {item name}_{categories}_{quantity}.JPG
fileName = fileName.replace(".JPG", "");
info = fileName.split("_"); // splits item name, category, and quantity into different variables
var itemName = info[0];
var category = info[1];
var quantity = info[2];
var hyperlink = '=HYPERLINK("' + link + '", "' + itemName + '")';
sheet.appendRow([hyperlink, category, quantity]);
}
}