cancel
Showing results for 
Search instead for 
Did you mean: 

Count a total of files into a folder with java script

sibiliojr
Champ in-the-making
Champ in-the-making
Hello everbody!
I need to calculate and create a report that contains a total of files into a space, and is necessary to show the total separately for each sub-space.
I found and know create a Web Script but I don't understand how can I navegate into spaces.
Please, if somebody knows I really appreciate.
Thank you very much.
5 REPLIES 5

romschn
Star Collaborator
Star Collaborator
You may get this done by writing a java-backed webscript and use the methods available from fileFolderService.

Take a look at below methods and you may choose the one suitable for you.
1. list()
2. listDeepFolders()
3. listFiles()
4. listFolders()

It will return a list and you can get the number of files from its size.

Hope this helps.

Thanks,

scouil
Star Contributor
Star Contributor
Hello,

It's also possible in javascript ofc.

Navigating in spaces can be done either by a classic search (like lucene):
var nodes = search.luceneSearch("");
Or by simply going down its path:
var node= companyhome.childByNamePath("your/folder/path");

Once you have your space, you can get an array of his children with
var children = node.children
and ofc the number of children with
var children = node.children.length

Hope this helps

jlabuelo
Champ on-the-rise
Champ on-the-rise
Hi there

Is it possible to modify this script to execute it in a space, so we can calculate the size of it.? I mean, using this script to get access to all its nodes and documents and add their size to a variable, so at the end of the loop we get the total size of an space.

If so, could you point me how? it is so difficult to obtain the size of a space…and seems to me something that should be much easier. (sure it is my fault Smiley Very Happy )

Thanks a lot

scouil
Star Contributor
Star Contributor
Let's assume that you fot the "children" variable with one of the techniques before:


function getSpaceSize() {
    var children; // cf previous posts to retrieve the expected value
    var spaceSize = 0;
    for each(var child in children) {
        spaceSize += child.size;
    }
    return spaceSize;
}

jlabuelo
Champ on-the-rise
Champ on-the-rise
Thanks a lot… will give it a try!!!