-
-
Save ichaer/d7b91d348a250e09146057857f7b3cc2 to your computer and use it in GitHub Desktop.
google script that lists information on google drive files and folders shared by link
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
var getFullPath = function(pathObj) { | |
var out = ''; | |
var sep = '/'; | |
var folderIter = pathObj.getParents(); | |
while(folderIter.hasNext()) { | |
out += sep + folderIter.next().getName(); | |
} | |
out += sep + pathObj.getName(); | |
return out; | |
}; | |
var arrJoin = function(arr, separator, val2str) { | |
separator = typeof separator !== 'undefined' ? separator : ', '; | |
val2str = typeof val2str !== 'undefined' ? val2str : function(v){return v}; | |
var out = ''; | |
var sep = ''; | |
for(i in arr) { | |
out += sep + val2str(arr[i]); | |
sep = separator; | |
} | |
return out; | |
} | |
function listFolders() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.appendRow(["Type","Path","Sharing Access", "Sharing Permission", "Get Editors", "Get Viewers", "Date", "Size", "URL", "Download", "Description"]); | |
var folders = DriveApp.getFolders(); | |
var sharedStuff = [ | |
['folder', DriveApp.searchFolders("visibility != 'limited' and 'me' in owners and trashed = false")], | |
['file', DriveApp.searchFiles("visibility != 'limited' and 'me' in owners and trashed = false")] | |
]; | |
for (var i in sharedStuff) { | |
if (!sharedStuff.hasOwnProperty(i)) { | |
continue; | |
} | |
var pathType = sharedStuff[i][0]; | |
var pathIterator = sharedStuff[i][1]; | |
while (pathIterator.hasNext()) { | |
var path = pathIterator.next(); | |
data = [ | |
pathType, | |
getFullPath(path), | |
path.getSharingAccess(), | |
path.getSharingPermission(), | |
arrJoin(path.getEditors(), ', ', function(v){return v.getEmail()}), | |
arrJoin(path.getViewers(), ', ', function(v){return v.getEmail()}), | |
path.getDateCreated(), | |
path.getSize(), | |
path.getUrl(), | |
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + path.getId(), | |
path.getDescription() | |
]; | |
sheet.appendRow(data); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
protip that I just discovered, might be worth adding a comment line for:
if you just replace the folder id with "root" that will scan the entire My Drive itself