douye2020 2014-11-23 18:56
浏览 65
已采纳

如何通过文件名(无扩展名)检查文件是否存在?

Question is quite self-explanatory.

Please, could anybody show me how can I check existence of the file by name (without extension) by short and efficient way. It would be great if code returns several occurrence if folder have several files with the same name.

Example:

folder/
  file.html
  file.md

UPDATE:

It is not obviously how to use one of filepath.Match() or filepath.Glob() functions by official documentation. So here is some examples:

matches, _          := filepath.Glob("./folder/file*") //returns paths to real files [folder/file.html, folder/file.md]
matchesToPattern, _ := filepath.Match("./folder/file*", "./folder/file.html") //returns true, but it is just compare strings and doesn't check real content
  • 写回答

2条回答 默认 最新

  • dongzi1209 2014-11-23 19:32
    关注

    You need to use the path/filepath package.

    The functions to check are: Glob(), Match() and Walk() — pick whatever suits your taste better.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大