Skip to content

Instantly share code, notes, and snippets.

@ichaer
Forked from woodwardtw/tellmeyoursecrets.js
Last active June 30, 2023 06:54
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ichaer/d7b91d348a250e09146057857f7b3cc2 to your computer and use it in GitHub Desktop.
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
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);
};
}
}
@thibaultmol
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment