Last active
November 25, 2021 06:41
-
-
Save Goblinlordx/170fa544a63424f348afc8aa886aea42 to your computer and use it in GitHub Desktop.
Go FS
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 ( | |
"flag" | |
"fmt" | |
"io/fs" | |
"log" | |
"os" | |
"path/filepath" | |
) | |
func main() { | |
flag.Parse() | |
args := flag.Args() | |
dirs := make(map[string]string) | |
fls := make(map[string]string) | |
for _, root := range args { | |
fs.WalkDir(os.DirFS(root), ".", func(path string, d fs.DirEntry, err error) error { | |
if path == "." { | |
return nil | |
} | |
if err != nil { | |
log.Fatal(err) | |
} | |
p := filepath.Join(root, path) | |
if d.IsDir() { | |
if _, ok := dirs[path]; !ok { | |
dirs[path] = p | |
} | |
} else { | |
if _, ok := fls[path]; !ok { | |
fls[path] = p | |
} | |
} | |
return nil | |
}) | |
} | |
for k, v := range dirs { | |
fmt.Printf("%s - %s\n", k, v) | |
} | |
fmt.Println("---") | |
for k, v := range fls { | |
fmt.Printf("%s - %s\n", k, v) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment