Created
April 12, 2018 15:13
-
-
Save Aaron-Macneill/427a15b22d283cfdb345839d5d29c7f8 to your computer and use it in GitHub Desktop.
ls clone in go. It's slightly faster than ls in directories with lots of files
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
package main | |
import ( | |
"fmt" | |
"github.com/fatih/color" | |
"io/ioutil" | |
) | |
var ( | |
fileColor = color.New(color.FgCyan) | |
folderColor = color.New(color.FgBlue, color.Bold) | |
hiddenColor = color.New(color.FgRed) | |
) | |
func main() { | |
files, err := ioutil.ReadDir(".") | |
if err != nil { | |
panic(err) | |
} | |
for _, file := range files { | |
if file.Name()[0] == '.' { | |
hiddenColor.Printf("%dB | %s\n", file.Size(), file.Name()) | |
continue | |
} | |
if file.IsDir() { | |
folderColor.Printf("%dB | %s\n", file.Size(), file.Name()) | |
continue | |
} else { | |
fileColor.Printf("%dB | %s\n", file.Size(), file.Name()) | |
} | |
} | |
fmt.Printf("\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment