ls: now it works properly.

This commit is contained in:
jienfak 2020-04-23 12:41:19 +05:00
parent 348ac923be
commit 12bb16228e

View file

@ -44,33 +44,31 @@ func Stat(p string) (os.FileInfo, error) {
} }
func ls(p string, fold int) error { func ls(p string, fold int) error {
if fold == 0 {
return nil
}
isDir, e := IsDir(p) isDir, e := IsDir(p)
if e != nil { if e != nil {
return e return e
} }
pp := strings.TrimRight(p, "/") pp := strings.TrimRight(p, "/")
if isDir && !dirFlag {
l, e := ReadDir(p)
if !isDir || dirFlag || fold<1 {
fmt.Println(pp);
}else{
l, e := ReadDir(pp)
if e!=nil { if e!=nil {
return e return e
} }
for _, f := range l { for _, f := range l {
s := pp+"/"+f.Name() s := pp+"/"+f.Name()
if b, _:=IsDir(s) ; b {
fmt.Println(s) fmt.Println(s)
}
if 0<fold {
ls(s, fold-1) ls(s, fold-1)
} }
} else {
f, e := Stat(p)
if e != nil {
return e
} }
fmt.Println(f.Name())
} }
return nil return nil
} }
@ -103,9 +101,10 @@ func Run(args []string) int {
fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e) fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e)
} else { } else {
for _, f := range l { for _, f := range l {
e := ls(f.Name(), foldLvl) e := ls(f.Name(), foldLvl-1)
if e!=nil { if e!=nil {
status = 1 status = 1
fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e)
} }
} }
} }