Last active
August 15, 2021 17:50
-
-
Save abdiasriver/1ba37b1d17642c578c4f155a7b741efa to your computer and use it in GitHub Desktop.
App script cambiar permisos a grupo de carpetas y archivos en GDRIVE
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
// Cambiar linea 5 el ID de la carpeta y en 18,19 y 80 a los permisos que desees | |
function changepermission() { | |
// folder principal de escaneado | |
var sourceID = "IDCARPETA"; // Coloca aqui el ID de tu folder | |
// Funcion para escanear sub-folders/files | |
folderAndFiles(sourceID); | |
} | |
function folderAndFiles(sourceID) { | |
// Obtener el folder principal | |
var folder = DriveApp.getFolderById(sourceID); | |
var newAccess = "PRIVATE"; // Permisos a buscar para comparar | |
var acceso = DriveApp.Access.PRIVATE; //PRIVATE o https://developers.google.com/apps-script/reference/drive/access?hl=es | |
var permisos = DriveApp.Permission.NONE; //VIEW o https://developers.google.com/apps-script/reference/drive/access?hl=es | |
// escanear todos los archivos del folder principal | |
var files = folder.getFiles(); | |
while(files.hasNext()) { | |
try { | |
// Obtener el siguiente next archivo en el folder | |
var file = files.next(); | |
// Obtener el nombre del archivo | |
var fileName = file.getName(); | |
// Mostrar Logger escaneado archivos | |
// checar accesos | |
var access = file.getSharingAccess(); | |
// check for match before attempting to change | |
if (access == newAccess) { | |
} | |
else { | |
cambiado = file.setSharing(acceso, permisos); | |
Logger.log('File name: ' + cambiado); | |
} | |
} | |
catch(e) { | |
Logger.log('Error: ' + fileName + e); | |
} | |
} | |
// Obtener todos los folders del principal | |
var childFolders = folder.getFolders(); | |
while(childFolders.hasNext()) { | |
try { | |
// Obtener el next folder | |
var child = childFolders.next(); | |
// Obtener el nombre del folder y mandar Logger | |
var childName = child.getName(); | |
Logger.log('Escaneado Folder: ' + childName); | |
child.setSharing(acceso, permisos); | |
// Obtener el ID del folder | |
var childId = child.getId(); | |
// pass Se reenvia la funcion ciclo pero con los subfolder a cambiar sub-files | |
folderAndFiles(childId); | |
} | |
catch(e) { | |
Logger.log('Problema en Folder: ' + e); | |
} | |
} | |
// Cambiar permisos compartir carpeta principal | |
folperm = folder.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.VIEW); | |
Logger.log('File name: ' + folperm); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tienes que usar app script para hacer funcionar este script