0% found this document useful (0 votes)
12 views2 pages

Google Drive Files Report

Excel shortcut

Uploaded by

zachious15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Google Drive Files Report

Excel shortcut

Uploaded by

zachious15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

WATCH FIRST: TIKTOK TUTORIAL LINK

Code to copy below

function listDriveFiles() {
const sheetId = 'SHEET ID REPLACE THIS';
const sheetName = 'SHEET NAME REPLACE THIS';
const sheet = SpreadsheetApp.openById(sheetId).getSheetByName(sheetName);
const mainFolderId = 'FOLDER ID REPLACE THIS';
const mainFolder = DriveApp.getFolderById(mainFolderId);

const data = getFilesInFolder(mainFolder);

sheet.getRange(2, 1, sheet.getLastRow(), 4).clearContent();


if (data.length > 0) {
sheet.getRange(2, 1, data.length, data[0].length).setValues(data);
}
}

function getFilesInFolder(folder, path = '') {


let data = [];
const files = folder.getFiles();
const folderPath = path + folder.getName() + '/';

while (files.hasNext()) {
const file = files.next();
const fileUrl = file.getUrl();
const fileNameWithLink = `=HYPERLINK("${fileUrl}","${file.getName()}")`;
const fileType = getFileType(file.getMimeType());
const dateCreated = file.getDateCreated();
const folderNameWithLink = `=HYPERLINK("${folder.getUrl()}","${folder.getName()}")`;

data.push([fileNameWithLink, folderNameWithLink, fileType, dateCreated]);


}

const subFolders = folder.getFolders();


while (subFolders.hasNext()) {
const subFolder = subFolders.next();
data = data.concat(getFilesInFolder(subFolder, folderPath));
}

return data;
}
function getFileType(mimeType) {
const typeMap = {
'image/jpeg': 'Photo',
'image/png': 'Photo',
'image/gif': 'Photo',
'video/mp4': 'Video',
'video/quicktime': 'Video',
'application/vnd.google-apps.spreadsheet': 'Spreadsheet',
'application/vnd.google-apps.document': 'Document',
'application/vnd.google-apps.presentation': 'Presentation',
// Add more mappings as needed
};

return typeMap[mimeType] || 'Other';


}

You might also like