3

I know there is NOT a direct way to get all files + folders of a hierarchy of BOX folder. we have to recursively get items of subfolders.

However, if I simply need a count estimation, is it possible to get the basic info?

The Transferring tool https://www.multcloud.com can estimate the file count firstly, after it is done, it will start the transferring. In my observation, it looks it also recursively iterates the folders, but how it can know the recursive has completed?

Thank you for any hints!

Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14

2 Answers2

0

If your tool is executed on the same machine on different dates, you can maintain some "estimation data" (i.e. persist the number of files of certain directories in a run, and use this old number of files contained in a subtree as estimation values for further runs)

Christoph Bimminger
  • 1,006
  • 7
  • 25
  • hi, thanks for the reply, but probably my post title is confusing.. I am looking for the BOX folder, instead of local machine directories. In addition, as mentioned, the transferring tool mulcloud.com can make such estimation, and start the transferring. It did not know my BOX folder hierarchy until it recursively iterates the folders and sub folders, but the point is how it knows the recursive has completed? – Xiaodong Liang Jan 14 '18 at 00:09
0

Hi finally found it is just a common question on how to determine a recursively iteration has completed. The other post helped a lot. How to detect completion of recursive asynchronous calls in javascript

With the hints, my code works well. The below is the script for reference. It can be converted to Promise. I have not tried, though.

        function buildTreeNodes(boxTopFolderId){ 

        function startBuild(){
            //get the top folder info
            box.folders.getItems(boxTopFolderId ,
            function (err, data) {

            var results = [];
            results.finished = 0; 
            var len = data.entries.length; 

            if (err){ 
            console.log(err);
            }
            else{ 

            //iterate from the top folder
            data.entries.forEach(function (item, index) {
                // BOX of file or folder
                var boxid = item.id;
                //  file or folder 
                var boxtype = item.type;
                //item name
                var boxname = item.name; 
                if(boxtype === 'folder'){
                recursiveFolder(boxid,function(result){
                    results[index] = result;
                    if (++results.finished == len) {

                        //recursion done!
                    }
                });
                }else{
                results[index] = item; 
                if (++results.finished == len) { 
                    //recursion done!
                } 
                }  
            }); //end for each 
            if(len == 0)
                //recursion done! 
        }  
        });
    }  
    function recursiveFolder(folderId,callback){

        box.folders.getItems(folderId,  
        function (err, data) {

            var results = [];
            results.finished = 0; 
            var len = data.entries.length; 

            if (err){ 
            console.log(err);
            }
            else{  

            //iterate from the top folder
            data.entries.forEach(function (item, index) {
                // BOX of file or folder
                var boxid = item.id;
                //  file or folder 
                var boxtype = item.type;
                //item name
                var boxname = item.name; 
                if(boxtype === 'folder'){

                recursiveFolder(boxid,function(result)
                    {
                    results[index] = result;
                    if (++results.finished == len) {
                    callback(results);
                    }
                });
                }
                else{
                results[index] = item;
                if (++results.finished == len){
                    callback(results);
                }  
                }    

            }); 
            if(len == 0)
                callback(results);

        }  
        }); 
    }
    startBuild();  

    }
Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14