Moodle Hack: Remove folder size calculation from moodle directory display

It is highly desirable to use moodle as a repository of very large resource collections (e.g. text CD's, document collections, software libraries etc).
This allows moodle users to navigate to content through moodle and directly link specific locations (e.g. the specific Yr9 chapter pdf) from within moodle with a URL that works the same at school or at home.

If large file collections are stored inside moodle this way, the system may slow or even "hang" as


function get_directory_size($rootdir, $excludefile='') {
Commented out to prevent time outs due to huge directory sizes in chelt moodle
global $CFG;
if (!empty($CFG->pathtodu) && is_executable(trim($CFG->pathtodu))) {
$command = trim($CFG->pathtodu).' -sk --apparent-size '.escapeshellarg($rootdir);
$output = null;
$return = null;
if (is_array($output)) {
return get_real_size(intval($output[0]).'k'); // we told it to return k.

if (!is_dir($rootdir)) { // Must be a directory
return 0;

if (!$dir = @opendir($rootdir)) { // Can't open it for some reason
return 0;

$size = 0;

while (false !== ($file = readdir($dir))) {
$firstchar = substr($file, 0, 1);
if ($firstchar == '.' or $file == 'CVS' or $file == $excludefile) {
$fullfile = $rootdir .'/'. $file;
if (filetype($fullfile) == 'dir') {
$size += get_directory_size($fullfile, $excludefile);
} else {
$size += filesize($fullfile);

return $size;
End of comment out */
return 1; /* function needs to return a value to avoid an error message */

No comments:

This post contains some responses to questions that I have been asked by various people over the last few years. In most cases, I have also posted the information on relevant online community forums such as I hope that you find this useful. Stephen Digby