Implement directory count info (#85)

This commit is contained in:
Karol Woźniak authored and gokcehan committed 2017-06-03 14:12:43 +03:00
1 parent 9962b378a8
commit fe05105c88
7 files changed
+38 -1

No files matched your search

+23 -1
View File
@@ -291,7 +291,29 @@ func (win *win) printd(dir *dir, marks map[string]int, saves map[string]bool) {
for _, s := range gOpts.info {
switch s {
case "size":
info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
if !(gOpts.dircounts && f.IsDir()) {
info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
continue
}
if f.Count == -1 {
d, err := os.Open(path)
if err != nil {
log.Printf("opening dir to read count: %s", err)
continue
}
names, err := d.Readdirnames(-1)
d.Close()
if err != nil {
log.Printf("reading dir count: %s", err)
continue
}
f.Count = len(names)
}
info = fmt.Sprintf("%s %d", info, f.Count)
case "time":
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
default: