October 2015
Beginner to intermediate
400 pages
14h 44m
English
In this section, we’ll build a program that reports the disk usage of
one or more directories specified on the command line, like the Unix
du command.
Most of its work is done by the walkDir function below, which
enumerates the entries of the directory dir using the
dirents helper function.
// walkDir recursively walks the file tree rooted at dir // and sends the size of each found file on fileSizes. func walkDir(dir string, fileSizes chan<- int64) { for _, entry := range dirents(dir) { if entry.IsDir() { subdir := filepath.Join(dir, entry.Name()) walkDir(subdir, fileSizes) } else { fileSizes <- entry.Size() } } } // dirents returns the entries of directory ...