Code: Select all
// Function for recursively counting bytes within a directory
get_recursive_byte_count = function(target_dir, entry_list){
byte_count = 0;
forEach(entry_list, function(file_name, index){
type = getTargetType(target_dir + file_name);
if(type === "dir"){
sub_target_dir = target_dir + file_name + getDirectorySeperator(s);
sub_dir = new Dir(sub_target_dir);
sub_file_list = sub_dir.entryList("*", Dir.Files|Dir.Dirs|Dir.NoDotAndDotDot, Dir.Name);
result_count = get_recursive_byte_count(sub_target_dir, sub_file_list);
} else if(type === "file"){
fs = new FileStatistics(target_dir + file_name);
byte_count += fs.getByteCount();
}
});
return byte_count;
}
Code: Select all
// Function for recursively counting files within a directory
get_recursive_file_count = function(target_dir, entry_list){
file_count = 0;
forEach(entry_list, function(file_name, index){
type = getTargetType(target_dir + file_name);
if(type === "dir"){
sub_target_dir = target_dir + file_name + getDirectorySeperator(s);
sub_dir = new Dir(sub_target_dir);
sub_file_list = sub_dir.entryList("*", Dir.Files|Dir.Dirs|Dir.NoDotAndDotDot, Dir.Name);
result_count = get_recursive_file_count(sub_target_dir, sub_file_list);
} else if(type === "file"){
file_count++;
}
});
return file_count;
}
Code: Select all
dir = new Dir( 'your_path_to_directory' );
file_list = dir.entryList("*", Dir.Files|Dir.Dirs|Dir.NoDotAndDotDot, Dir.Name);
count = get_recursive_file_count(prop.target_url, file_list);