闲的无聊贴个显示/隐藏文件的代码,因为经常要用
mac
package main import ( "fmt" "os" "strings" "os/exec" ) func show() { cmd := exec.Command("/bin/bash","-c","defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder") _, err := cmd.Output() if err != nil { fmt.Println("运行失败: " + err.Error()) return }else { fmt.Println("运行成功") } } func hide() { cmd := exec.Command("/bin/bash","-c","defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder") _, err := cmd.Output() if err != nil { fmt.Println("运行失败: " + err.Error()) return }else { fmt.Println("运行成功") } } func main() { argNum := len(os.Args) if argNum == 1{ fmt.Println("缺少参数, show或hide") return } shouldShow := os.Args[1] if strings.EqualFold("show",shouldShow){ show() } if strings.EqualFold("hide",shouldShow){ hide() } }