Created
August 10, 2019 22:50
-
-
Save selfup/a4ba9befad13ae7d9602b77acf65aefb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"os" | |
"path/filepath" | |
"strconv" | |
) | |
func main() { | |
var dir string | |
var size int64 | |
if len(os.Args) == 3 { | |
dir = os.Args[1] | |
sizeInt, err := strconv.Atoi(os.Args[2]) | |
if err != nil { | |
panic(err) | |
} | |
size = int64(sizeInt) | |
} | |
scnnr := FindBySize{ | |
Directory: dir, | |
Size: size, | |
} | |
err := scnnr.Scan() | |
if err != nil { | |
panic(err) | |
} | |
} | |
// FindBySize holds cli args | |
type FindBySize struct { | |
Directory string | |
Size int64 | |
Found []string | |
} | |
// Scan walks the given directory tree | |
func (f *FindBySize) Scan() error { | |
err := filepath.Walk(f.Directory, f.scan) | |
if err != nil { | |
return err | |
} | |
return nil | |
} | |
func (f *FindBySize) scan(path string, info os.FileInfo, err error) error { | |
if err != nil { | |
return err | |
} | |
if !info.IsDir() { | |
if info.Size() > f.Size { | |
f.Found = append(f.Found, path) | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment