/*--- title: Walk, glob and sort group: Files summary: Find files with glob patterns and walk a whole drive. ---*/ requirelib("filelib"); // glob only expands wildcards in the file name part. var images = filelib.glob("user:/Photo/*.jpg").concat(filelib.glob("user:/Photo/*.png")); // A second argument picks the sort mode: smart, mostRecent, largeToSmall, ... var bySize = filelib.glob("user:/Documents/*", "largeToSmall"); // walk lists everything below a folder; "file" or "folder" filters it. var allFiles = filelib.walk("user:/", "file"); var total = 0; for (var i = 0; i < allFiles.length; i++) { total += filelib.filesize(allFiles[i]); } sendJSONResp({ images: images, documentsLargestFirst: bySize, fileCount: allFiles.length, totalBytes: total });