From 810252a00e9a4b8f91a034011d46b4c32d54ee69 Mon Sep 17 00:00:00 2001 From: john Date: Fri, 26 Oct 2018 18:39:03 +0800 Subject: [PATCH] =?UTF-8?q?gfile.ScanDir=E6=94=AF=E6=8C=81pattern=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E6=96=87=E4=BB=B6=E6=A8=A1=E5=BC=8F=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8','=E7=AC=A6=E5=8F=B7=E5=88=86?= =?UTF-8?q?=E9=9A=94=E5=A4=9A=E4=B8=AA=E5=8C=B9=E9=85=8D=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/os/gfile/gfile.go | 9 ++++++--- geg/other/test2.go | 12 ++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index 6b99d9435..9a00eaed7 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -251,7 +251,8 @@ func ScanDir(path string, pattern string, recursive ... bool) ([]string, error) return list, nil } -// 内部检索目录方法,支持递归,返回没有排序的文件绝对路径列表结果 +// 内部检索目录方法,支持递归,返回没有排序的文件绝对路径列表结果。 +// pattern参数支持多个文件名称模式匹配,使用','符号分隔多个模式。 func doScanDir(path string, pattern string, recursive ... bool) ([]string, error) { var list []string // 打开目录 @@ -275,8 +276,10 @@ func doScanDir(path string, pattern string, recursive ... bool) ([]string, error } } // 满足pattern才加入结果列表 - if match, err := filepath.Match(pattern, name); err == nil && match { - list = append(list, path) + for _, p := range strings.Split(pattern, ",") { + if match, err := filepath.Match(strings.TrimSpace(p), name); err == nil && match { + list = append(list, path) + } } } return list, nil diff --git a/geg/other/test2.go b/geg/other/test2.go index ce69175ff..933d8ed0b 100644 --- a/geg/other/test2.go +++ b/geg/other/test2.go @@ -2,17 +2,9 @@ package main import ( "gitee.com/johng/gf/g" - "gitee.com/johng/gf/g/net/ghttp" + "gitee.com/johng/gf/g/os/gfile" ) func main() { - s := g.Server() - s.BindHandler("/{class}-{course}/:name/*act", func(r *ghttp.Request){ - r.Response.Writeln(r.Get("class")) - r.Response.Writeln(r.Get("course")) - r.Response.Writeln(r.Get("name")) - r.Response.Writeln(r.Get("act")) - }) - s.SetPort(8199) - s.Run() + g.Dump(gfile.ScanDir("/var/log", "*.log, *.gz", true)) } \ No newline at end of file