草庐IT

filePath

全部标签

go - Walk文件夹时如何过滤子文件夹

现在我正在使用Walk浏览我的文件夹,我想在扫描时过滤一些文件夹。err:=filepath.Walk("/home",func(pathstring,fos.FileInfo,errerror)error{...})文件夹结构是:home/|\abc我可以做一些异常(exception)列表filepath.Walk不扫描文件夹a吗?也就是说,我不想将文件夹a中的任何文件添加到我的扫描结果中。 最佳答案 来自WalkFuc的文档:Ifanerrorisreturned,processingstops.Thesoleexceptio

转到错误 : "multiple-value filepath.Glob() in single-value context"

谁能解释一下为什么这行代码:varfile_list[]string=filepath.Glob(os.Getwd()+"/*.*")正在生成这些错误:multiple-valueos.Getwd()insingle-valuecontextmultiple-valuefilepath.Glob()insingle-valuecontext谢谢!布莱恩 最佳答案 两者都返回错误,因此您不能直接分配它们。funcGlob(patternstring)(matches[]string,errerror)funcGetwd()(dirst

转到错误 : "multiple-value filepath.Glob() in single-value context"

谁能解释一下为什么这行代码:varfile_list[]string=filepath.Glob(os.Getwd()+"/*.*")正在生成这些错误:multiple-valueos.Getwd()insingle-valuecontextmultiple-valuefilepath.Glob()insingle-valuecontext谢谢!布莱恩 最佳答案 两者都返回错误,因此您不能直接分配它们。funcGlob(patternstring)(matches[]string,errerror)funcGetwd()(dirst

search - 如何通过基本名称(不带扩展名)检查文件是否存在?

问题是不言自明的。谁能告诉我如何通过简短有效的方式按名称(不带扩展名)检查文件是否存在。如果文件夹中有多个同名文件,如果代码返回多次出现,那就太好了。例子:folder/file.htmlfile.md更新:官方文档没有明确说明如何使用filepath.Match()或filepath.Glob()函数之一。所以这里有一些例子:matches,_:=filepath.Glob("./folder/file*")//returnspathstorealfiles[folder/file.html,folder/file.md]matchesToPattern,_:=filepath.Ma

search - 如何通过基本名称(不带扩展名)检查文件是否存在?

问题是不言自明的。谁能告诉我如何通过简短有效的方式按名称(不带扩展名)检查文件是否存在。如果文件夹中有多个同名文件,如果代码返回多次出现,那就太好了。例子:folder/file.htmlfile.md更新:官方文档没有明确说明如何使用filepath.Match()或filepath.Glob()函数之一。所以这里有一些例子:matches,_:=filepath.Glob("./folder/file*")//returnspathstorealfiles[folder/file.html,folder/file.md]matchesToPattern,_:=filepath.Ma

windows - 如何使用 golang 在 Windows 上获取正确的文件基名

packagemainimport("fmt""path")funcmain(){p:="./p/p"q:=".\\q\\q"fmt.Println(path.Base(p))fmt.Println(path.Base(q))}我在Windows上运行它,输出是:p.\q\q我认为path.Base返回错误答案。那么我怎样才能得到正确的文件基名。 最佳答案 应使用path/filepath执行特定于平台的路径操作包而不是path.来自文档:Packagefilepathimplementsutilityroutinesformani

windows - 如何使用 golang 在 Windows 上获取正确的文件基名

packagemainimport("fmt""path")funcmain(){p:="./p/p"q:=".\\q\\q"fmt.Println(path.Base(p))fmt.Println(path.Base(q))}我在Windows上运行它,输出是:p.\q\q我认为path.Base返回错误答案。那么我怎样才能得到正确的文件基名。 最佳答案 应使用path/filepath执行特定于平台的路径操作包而不是path.来自文档:Packagefilepathimplementsutilityroutinesformani

go - 如何将 Map 传递给 Go 中的回调函数

我正在尝试编写一个Go程序来遍历目录并找到特定文件并将该信息存储在Map中。这是我到目前为止所拥有的。我不确定如何将Map传递给访问函数,因为它是一个回调函数。..typeMyFilestruct{NamestringFilePathstringFileMD5Hash[16]byte}funcvisit(pathstring,fos.FileInfo,errerror)error{fileName:=f.Name()if!f.IsDir()&&strings.Contains(strings.ToLower(fileName),"myfile"){df:=parseFile(path)

go - 如何将 Map 传递给 Go 中的回调函数

我正在尝试编写一个Go程序来遍历目录并找到特定文件并将该信息存储在Map中。这是我到目前为止所拥有的。我不确定如何将Map传递给访问函数,因为它是一个回调函数。..typeMyFilestruct{NamestringFilePathstringFileMD5Hash[16]byte}funcvisit(pathstring,fos.FileInfo,errerror)error{fileName:=f.Name()if!f.IsDir()&&strings.Contains(strings.ToLower(fileName),"myfile"){df:=parseFile(path)

go - 为什么 filepath.Walk() panic ?

我正在尝试为go编程语言编写wiki。我已将数据放在/data文件夹中,将.html文件放在/tmpl文件夹中。我将main函数编码如下funcmain(){walk:=func(pathstring,infoos.FileInfo,errerror)error{iferr==nil&&!info.IsDir()&&filepath.Ext(path)==".html"{http.HandleFunc("/view/",makeHandler(viewHandler))http.HandleFunc("/edit/",makeHandler(editHandler))http.Hand