|
@@ -10,8 +10,17 @@ import (
|
|
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
|
// dirTree(os.Stdout, "..", true)
|
|
// dirTree(os.Stdout, "..", true)
|
|
|
- foo("", os.Stdout, "..", false)
|
|
|
|
|
- // foo("..", false)
|
|
|
|
|
|
|
+ foo("", os.Stdout, "..", true)
|
|
|
|
|
+ // sizeTest()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func sizeTest() {
|
|
|
|
|
+ fileInfo, err := os.Stat("foo1.go")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Println("!")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fmt.Println(fileInfo.Size(), err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func dirTree(output io.Writer, currDir string, printFile bool) error {
|
|
func dirTree(output io.Writer, currDir string, printFile bool) error {
|
|
@@ -53,6 +62,7 @@ func foo(prependingString string, output io.Writer, dir string, print bool) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
length = len(files)
|
|
length = len(files)
|
|
|
|
|
+
|
|
|
for i, file := range files {
|
|
for i, file := range files {
|
|
|
if file.IsDir() {
|
|
if file.IsDir() {
|
|
|
var stringPrepender string
|
|
var stringPrepender string
|
|
@@ -64,10 +74,27 @@ func foo(prependingString string, output io.Writer, dir string, print bool) {
|
|
|
stringPrepender = prependingString + "\t"
|
|
stringPrepender = prependingString + "\t"
|
|
|
}
|
|
}
|
|
|
newDir := filepath.Join(dir, file.Name())
|
|
newDir := filepath.Join(dir, file.Name())
|
|
|
-
|
|
|
|
|
- fmt.Println("newDir", newDir, stringPrepender)
|
|
|
|
|
|
|
+ foo(stringPrepender, output, newDir, print)
|
|
|
|
|
+ } else if print {
|
|
|
|
|
+ fileInfo, err := file.Info()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Fatalf("Could not get fileInfo for %s:", file.Name())
|
|
|
|
|
+ }
|
|
|
|
|
+ size := fileInfo.Size()
|
|
|
|
|
+ if size > 0 {
|
|
|
|
|
+ if length > i+1 {
|
|
|
|
|
+ fmt.Fprintf(output, prependingString+"├───%s (%vb)\n", file.Name(), size)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt.Fprintf(output, prependingString+"└───%s (%vb)\n", file.Name(), size)
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if length > i+1 {
|
|
|
|
|
+ fmt.Fprintf(output, prependingString+"├───%s (empty)\n", file.Name())
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt.Fprintf(output, prependingString+"└───%s (empty)\n", file.Name())
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|