-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package big | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
) | ||
|
||
func Files(fsys fs.FS, size int64) (int64, error) { | ||
var count int64 | ||
err := fs.WalkDir(fsys, ".", func(p string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
info, err := d.Info() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("%s: [%s]\n", info.Name(), ByteCountIEC(info.Size())) | ||
|
||
if info.Size() >= size { | ||
count++ | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return count, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package big | ||
|
||
import "fmt" | ||
|
||
func ByteCountSI(b int64) string { | ||
const unit = 1000 | ||
if b < unit { | ||
return fmt.Sprintf("%d B", b) | ||
} | ||
div, exp := int64(unit), 0 | ||
for n := b / unit; n >= unit; n /= unit { | ||
div *= unit | ||
exp++ | ||
} | ||
return fmt.Sprintf("%.1f %cB", | ||
float64(b)/float64(div), "kMGTPE"[exp]) | ||
} | ||
|
||
func ByteCountIEC(b int64) string { | ||
const unit = 1024 | ||
if b < unit { | ||
return fmt.Sprintf("%d B", b) | ||
} | ||
div, exp := int64(unit), 0 | ||
for n := b / unit; n >= unit; n /= unit { | ||
div *= unit | ||
exp++ | ||
} | ||
return fmt.Sprintf("%.1f %ciB", | ||
float64(b)/float64(div), "KMGTPE"[exp]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/davemolk/scripts/big" | ||
) | ||
|
||
|
||
func main() { | ||
var dir string | ||
var size int64 | ||
flag.StringVar(&dir, "d", ".", "directory to start walk") | ||
flag.Int64Var(&size, "s", 0, "minimum file size") | ||
flag.Parse() | ||
|
||
c, err := big.Files(os.DirFS(dir), size) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
fmt.Println(c) | ||
} |