Last active
April 9, 2019 15:02
-
-
Save shingorow/930de6fb354b89a70ea384899f5a7517 to your computer and use it in GitHub Desktop.
Get a file list in Google Drive folder and write it to Spreadsheet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFileListInFolder() { | |
var url = 'https://drive.google.com/drive/folders/(GoogleDrive folder ID)', // URL of Google Drive folder. | |
paths = url.split('/'), // Separate URL into an array of strings by separating the string into substrings. | |
folderId = paths.pop(), // Get a last element of paths array. | |
folder = DriveApp.getFolderById(folderId), | |
files = folder.getFiles(), | |
list = [], | |
rowIndex = 1, // The starting row of a range. | |
colIndex = 1, // The starting row of a column. | |
ss, sheet,range, | |
sheetName = 'シート1', | |
currentRange, | |
file; | |
// Creating a data array from a files iterator. | |
while(files.hasNext()) { | |
file = files.next(); | |
list.push([file.getName(), file.getUrl()]); | |
}; | |
ss = SpreadsheetApp.getActive(); | |
sheet = ss.getSheetByName(sheetName); | |
range = sheet.getRange(rowIndex, colIndex, list.length, list[0].length); | |
currentRange = range.getDataRange().offset(1, 0); | |
currentRange.clear(); | |
range.setValues(list); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment