04-24-2013 01:26 PM
//
// Script to recursively descend into sites and count files in document libraries
//
var count = 0;
// Get an array of all site nodes
var sites = siteService.listSites(null,null,0);
// Loop over sites
for each (var site in sites) {
//logger.log("Site: " + site.shortName);
// First, find files at the top level in /documentLibrary (excluding subfolders)
// Loop over the sites's children (doclib, wiki/blog, etc.)
for each (child in site.node.children) {
// Loop over the children of doclib/wiki/blog and get files in the doclib
for each (item in child.children) {
// Find unique files
ufile = unique(item);
if (ufile.isDocument && ufile.displayPath.match(/documentLibrary/)) {
//logger.log(" " + ufile.displayPath + "/" + ufile.name);
count++;
}
}
}
// Now add the file nodes in /documentLibrary subfolders
getSpaces (site.node, 0);
}
logger.log("Total: " + count);
// Function to find every file in a doclib subfolder in a site
function getSpaces (node, depth) {
// Recursively descend into folders and files all files
if (node.isContainer) {
//logger.log("Folder: " + node.displayPath + "/" + node.name);
for each (var file in node.children) {
if (file.displayPath.match(/documentLibrary/) && file.isDocument) {
//logger.log(" " + file.displayPath + "/" + file.name);
count++;
}
}
}
var children = node.children;
for each (var child in children) {
if (child.isContainer && node.children.size != 0) {
getSpaces(child, depth++);
}
}
}
// Function to find unique members of an array
function unique (origArr) {
var newArr = [];
found = undefined;
x = 0;
y = 0;
origLen = origArr.length,
found,
x, y;
for ( x = 0; x < origLen; x++ ) {
found = undefined;
for ( y = 0; y < newArr.length; y++ ) {
if ( origArr[x] === newArr[y] ) {
found = true;
break;
}
}
if ( !found) newArr.push( origArr[x] );
}
return newArr;
};
05-28-2013 08:11 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.