Thanks that's great. I get the following error message though:
Can not find data record in database table course_modules.
$folder = $DB->get_records_sql("SELECT {folder}.id FROM {folder} WHERE course = '$courseid'");
$count = 0;
$folders = 0;
foreach ($folder as $fo){
//files within folders
$cm = get_coursemodule_from_id('folder', $fo->id);
$context = context_module::instance($cm->id);
$contextid = $context->id;
$files = $fs->get_area_files($contextid, 'mod_folder', 'content', false, '', false);
$folders += count($files);
}
Your help is greatly appreciated.