草庐IT

安卓目录

全部标签

go - 来自 os.Stat/Lstat 的目录大小

假设我在目录上执行os.Stat():funcmain(){fi,_:=os.Stat("/tmp")println(fi.Size())}//548//Programexited.https://play.golang.org/p/NIzGMHRYfi[FileInfo].Size()值究竟代表什么?这不是文件大小,所以我猜是文件数量之类的东西?inode?我在任何地方都找不到明确的答案,所以也许有人可以启发我? 最佳答案 FileInfo提及//lengthinbytesforregularfiles;system-depend

go - 如果特定目录上有 mount --bind,如何检查 golang?

我使用以下命令检查目录是否已挂载。res:=exec.Command("mount","|","grep",toDir,">","/dev/null").Run()但是无论目录是否挂载,它都会返回exitstatus1。挂载|grep/path/to/dir>/dev/null在命令行上工作正常。如何获取信息? 最佳答案 由于您的命令涉及管道,您可以将其作为命令字符串传递给bash,而不是直接执行它。这样的事情应该有效。packagemainimport("fmt""os/exec")funcmain(){res,_:=exec.C

go - 默认情况下是否可能不包含子目录中的 Golang 包?

我正在使用一个golang包,说名字pkgfoo;并且作者明确表示,如果我们想在pkgfoo下使用包subpkg,我需要显式导入subpkg。我不明白背后的原因。我在Golang中导入toppkg是不是自动导入了subpkg?packagemainimport("myownpackage""github.com/usera/pkgfoo""github.com/usera/pkgfoo/subpkg")funcmain(){//Usefunctionsinpkgfoo,andusefunctionsinpkgfoo/subpkg//......http.HandleFunc("/log

如果我在 .go 文件目录之外,go 安装会失败

我通过建议安装了Golanghttps://golang.org/doc/install而且我似乎无法像他们在网站上那样运行goinstall命令如果我从.go文件所在目录以外的任何目录运行该命令,则会出现此错误。例如:goinstall./src/tutorial/helloworld/hello.go或goinstall./path/to/.go/file/hello.gogoinstall:noinstalllocationfor.gofileslistedoncommandline(GOBINnotset)但是如果我从包含.go文件的目录中运行安装,一切都会顺利进行,它会将最终

go - 一个滑行项目应该如何导入另一个带有 vendor/目录的项目?

golangGlide打包器会自动为项目安装依赖项,然而,在这样做时它会从vendor/拉取依赖项,因为许多项目会检查vendor依赖项。应该如何导入包含vendor/目录的glide依赖项?截至目前,您可能会遇到如下错误:./scheduler.go:36:不能使用“github.com/jayunit100/my-project/vendor/github.com/spf13/pflag”.CommandLine(类型*“github.com/jayunit100/my-项目/vendor/a/b/spf13/pflag".FlagSet)作为类型*"github.com/jayu

go - 在 golang 中使用 os/exec 在特定目录中执行命令

我想在特定目录中运行一个命令。所以这里有两种方法可以做到这一点。command:=exec.Command("echo*tar.gz|xargs-n1tarzxf")command.Dir=pathFinalcmdErr:=command.Run()另一方面,这对我不起作用,command:="cd"+pathFinal+";"+"echo*tar.gz|xargs-n1tarzxf"cmd:=exec.Command("/bin/sh","-c",command)cmdErr:=command.Run()这是有效的。我想以第一种方式实现它。我不知道为什么它不起作用第二个抛出错误无法解

Golang : pass boolean flag from function in file/sub-directory A, 在文件/子目录 B 中运行

以下函数位于文件夹go-ethereum/core/vm/instructions.go中:funcopAdd(pc*uint64,evm*EVM,contract*Contract,memory*Memory,stack*Stack)([]byte,error){//beginexecutiontimetrackingvarstartTime=time.Now().UnixNano();x,y:=stack.pop(),stack.pop()stack.push(math.U256(x.Add(x,y)))evm.interpreter.intPool.put(y)//logella

去获取父目录

我有一些命令行程序需要从父文件夹中读取文件,我的意思是-parentDir--myproject---cmd----main.go--otherdir-file.json如您所见,otherdir就像是myproject的兄弟,我需要从我的main.go中读取file.json我试过的就像下面这样funcvisit(pathstring,fos.FileInfo,errerror)error{fmt.Printf("Visited:%s\n",path)returnnil}funcmain(){flag.Parse()root:=flag.Arg(0)err:=filepath.Wal

go - 获取golang中目录的校验和

有没有办法在golang中生成整个目录及其内容的校验和?我知道那个人如何对目录进行压缩,然后获取该目录的校验和,但我想尽可能避免这种情况。 最佳答案 检查Paralleldigestion来自https://blog.golang.org/pipelines的示例,从Digestingatree部分开始,可能会给您一些想法。所以你可以从://MD5Allreadsallthefilesinthefiletreerootedatrootandreturnsamap//fromfilepathtotheMD5sumofthefile's

go - fork /执行。没有这样的文件或目录退出状态 1

我在Mac(darwin/amd64)上使用Go1.10.2并遇到这个错误。它说没有这样的文件或目录。这是我的代码,funcloop1(gor_namestring,ras_ipstring){varastringvarcstringa=search_path()fmt.Printf("当前路径为",a)fmt.Println(os.Chdir(a))c=fmt.Sprintf("%s%s%s%s","./goreplay--input-file",gor_name,"--input-file-loop--output-http",ras_ip)fmt.Printf("c:",c)cm