当前位置: 首页>>代码示例>>Golang>>正文


Golang filepath.Glob函数代码示例

本文整理汇总了Golang中path/filepath.Glob函数的典型用法代码示例。如果您正苦于以下问题:Golang Glob函数的具体用法?Golang Glob怎么用?Golang Glob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Glob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: cleanOldCache

//
// Clear out any old rec*.xml.bz2 or titlecache.txt files
//
func cleanOldCache() {
	recs, _ := filepath.Glob(filepath.Join(conf["data_dir"], "rec*.xml.bz2"))
	tfs, _ := filepath.Glob(conf["title_file"])
	dfs, _ := filepath.Glob(conf["dat_file"])

	// If any old record or title cache files exist, give the user an opportunity
	// to ctrl-c to cancel this.

	if len(recs) > 0 || len(tfs) > 0 || len(dfs) > 0 {
		fmt.Println("Old record and/or title cache file exist. Removing in 5 seconds ...")
		time.Sleep(5000000000)
	}

	if len(recs) > 0 {
		fmt.Println("Removing old record files . . .")
		for _, fp := range recs {
			os.Remove(fp)
		}
	}

	if len(tfs) > 0 {
		fmt.Println("Removing old title file . . .")
		for _, fp := range tfs {
			os.Remove(fp)
		}
	}

	if len(dfs) > 0 {
		fmt.Println("Removing old dat file . . .")
		for _, fp := range dfs {
			os.Remove(fp)
		}
	}
}
开发者ID:aiviru,项目名称:bzwikipedia,代码行数:37,代码来源:main.go

示例2: loadLogos

func loadLogos(context appengine.Context, globpaths ...string) map[string][]image.Image {
	logoImagesByName := make(map[string][]image.Image)

	for _, path := range globpaths {
		logoFolders, err := filepath.Glob(path + "/*")
		check(err, context)

		for _, logoFolder := range logoFolders {
			logoFiles, err := filepath.Glob(logoFolder + "/*")
			check(err, context)

			filename := filepath.Base(logoFolder)
			logoImages := make([]image.Image, 0)

			for _, logoFile := range logoFiles {
				//fmt.Fprintf(os.Stderr, "%s\n", logoFile)
				logoData, err := os.Open(logoFile)
				defer logoData.Close()
				check(err, context)

				reader := bufio.NewReader(logoData)
				logoImage, err := png.Decode(reader)
				check(err, context)

				logoImages = append(logoImages, logoImage)
			}

			logoImagesByName[filename] = logoImages

		}
	}

	return logoImagesByName
}
开发者ID:pyisoeyz,项目名称:chaparty,代码行数:34,代码来源:logos.go

示例3: loadActions

func (context *Context) loadActions(action string) template.HTML {
	var actions = map[string]string{}
	var actionKeys = []string{}
	var viewPaths = context.getViewPaths()

	for j := len(viewPaths); j > 0; j-- {
		view := viewPaths[j-1]
		globalfiles, _ := filepath.Glob(path.Join(view, "actions/*.tmpl"))
		files, _ := filepath.Glob(path.Join(view, "actions", action, "*.tmpl"))

		for _, file := range append(globalfiles, files...) {
			if _, ok := actions[path.Base(file)]; !ok {
				actionKeys = append(actionKeys, path.Base(file))
			}
			base := regexp.MustCompile("^\\d+\\.").ReplaceAllString(path.Base(file), "")
			actions[base] = file
		}
	}

	sort.Strings(actionKeys)

	var result = bytes.NewBufferString("")
	for _, key := range actionKeys {
		base := regexp.MustCompile("^\\d+\\.").ReplaceAllString(key, "")
		file := actions[base]
		if tmpl, err := template.New(path.Base(file)).Funcs(context.FuncMap()).ParseFiles(file); err == nil {
			if err := tmpl.Execute(result, context); err != nil {
				panic(err)
			}
		}
	}
	return template.HTML(strings.TrimSpace(result.String()))
}
开发者ID:kennylixi,项目名称:qor,代码行数:33,代码来源:func_map.go

示例4: initTemplates

func initTemplates() error {
	if templates == nil {
		templates = make(map[string]*template.Template)
	}

	templatesDir := "./templates/"

	layouts, err := filepath.Glob(templatesDir + "layouts/*.tmpl")

	if err != nil {
		return err
	}

	pages, err := filepath.Glob(templatesDir + "pages/*.tmpl")

	if err != nil {
		return err
	}

	for _, page := range pages {
		files := append(layouts, page)
		filename := filepath.Base(page)

		var err error

		templates[filename], err = template.New(filename).Funcs(template.FuncMap{"osIcon": osIcon}).ParseFiles(files...)

		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:cj123,项目名称:canijailbreak.com,代码行数:34,代码来源:template.go

示例5: Run

// Run Gzipbeat.
func (gb *Gzipbeat) Run(b *beat.Beat) error {

	// iterate through each config section
	for _, input := range gb.config.Input {

		// list all gzip files in directory
		gzips, _ := filepath.Glob(input.Path)
		if input.Exclude != "" {
			exclude, _ := filepath.Glob(input.Exclude)
			gzips = diff(gzips, exclude)
		}
		gzips = diff(gzips, gb.registry)

		// do 1 file at the time
		for _, filename := range gzips {
			send(gb, filename, &input.Fields)
			err := saveToRegistry(gb, filename)
			if err != nil {
				logp.Err("Error saving to registry file %s: %v", gb.config.Registry, err)
				return err
			}
		}
	}

	return nil
}
开发者ID:mmuszkow,项目名称:gzipbeat,代码行数:27,代码来源:gzipbeat.go

示例6: analogRead

func (a *analogPin) analogRead() int {
	var err error
	var fi *os.File

	ocp, err := filepath.Glob(Ocp)
	if err != nil {
		panic(err)
	}

	helper, err := filepath.Glob(fmt.Sprintf("%v/helper.*", ocp[0]))
	if err != nil {
		panic(err)
	}

	fi, err = os.Open(fmt.Sprintf("%v/%v", helper[0], a.pinNum))
	if err != nil {
		panic(err)
	}

	var buf = make([]byte, 1024)
	fi.Read(buf)
	fi.Close()

	i, _ := strconv.Atoi(strings.Split(string(buf), "\n")[0])
	return i
}
开发者ID:ninetwentyfour,项目名称:gobot,代码行数:26,代码来源:analog_pin.go

示例7: TestCopyDataDoIdempotent

func (s *copydataSuite) TestCopyDataDoIdempotent(c *C) {
	// make sure that a retry wouldn't stumble on partial work

	v1 := snaptest.MockSnap(c, helloYaml1, helloContents, &snap.SideInfo{Revision: snap.R(10)})

	s.populateData(c, snap.R(10))
	homedir := s.populateHomeData(c, "user1", snap.R(10))

	// pretend we install a new version
	v2 := snaptest.MockSnap(c, helloYaml2, helloContents, &snap.SideInfo{Revision: snap.R(20)})

	// copy data
	err := s.be.CopySnapData(v2, v1, &s.nullProgress)
	c.Assert(err, IsNil)

	err = s.be.CopySnapData(v2, v1, &s.nullProgress)
	c.Assert(err, IsNil)

	v2data := filepath.Join(dirs.SnapDataDir, "hello/20")
	l, err := filepath.Glob(filepath.Join(v2data, "*"))
	c.Assert(err, IsNil)
	c.Assert(l, HasLen, 1)
	v2HomeData := filepath.Join(homedir, "hello/20")
	l, err = filepath.Glob(filepath.Join(v2HomeData, "*"))
	c.Assert(err, IsNil)
	c.Assert(l, HasLen, 1)
}
开发者ID:pedronis,项目名称:snappy,代码行数:27,代码来源:copydata_test.go

示例8: RemoveFiles

// RemoveFiles removes old compiled files for this group from dst
func (g *Group) RemoveFiles(dst string) error {

	if dst == "" {
		return fmt.Errorf("Empty destination string")
	}

	var assets []string

	pattern := path.Join(dst, "assets", "scripts", g.name+"-*.min.js")
	files, err := filepath.Glob(pattern)
	if err != nil {
		return err
	}

	assets = append(assets, files...)
	pattern = path.Join(dst, "assets", "styles", g.name+"-*.min.css")
	files, err = filepath.Glob(pattern)
	if err != nil {
		return err
	}
	assets = append(assets, files...)

	for _, a := range assets {
		err = os.Remove(a)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:fragmenta,项目名称:assets,代码行数:32,代码来源:group.go

示例9: collectGitOrphans

// collectGitOrphans deletes all repos in dataPath except the one pointed to by
// a git deployer's "current" symlink.
// Errors are generally ignored; some are logged. If current does not exist, *all*
// repos are orphans, and all will be deleted; this should only be the case when
// converting a gitDeployer to a manifestDeployer.
func collectGitOrphans(dataPath string) {
	current, err := symlink.Read(filepath.Join(dataPath, gitCurrentPath))
	if os.IsNotExist(err) {
		logger.Debugf("no current staging repo")
	} else if err != nil {
		logger.Warningf("cannot read current staging repo: %v", err)
		return
	} else if !filepath.IsAbs(current) {
		current = filepath.Join(dataPath, current)
	}
	orphans, err := filepath.Glob(filepath.Join(dataPath, fmt.Sprintf("%s*", gitUpdatePrefix)))
	if err != nil {
		return
	}
	installOrphans, err := filepath.Glob(filepath.Join(dataPath, fmt.Sprintf("%s*", gitInstallPrefix)))
	if err != nil {
		return
	}
	orphans = append(orphans, installOrphans...)
	for _, repoPath := range orphans {
		if repoPath != dataPath && repoPath != current {
			if err = os.RemoveAll(repoPath); err != nil {
				logger.Warningf("failed to remove orphan repo at %s: %s", repoPath, err)
			}
		}
	}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:32,代码来源:git_deployer.go

示例10: runLs

func runLs(cmd *flagplus.Subcommand, args []string) {
	if !*IsCert && !*IsRequest && !*IsKey {
		*IsCert = true
		*IsRequest = true
		*IsKey = true
	}

	if *IsCert {
		match, err := filepath.Glob(filepath.Join(Dir.Cert, "*"+EXT_CERT))
		if err != nil {
			log.Fatal(err)
		}
		printCert(match)
	}
	if *IsRequest {
		match, err := filepath.Glob(filepath.Join(Dir.Root, "*"+EXT_REQUEST))
		if err != nil {
			log.Fatal(err)
		}
		printCert(match)
	}
	if *IsKey {
		match, err := filepath.Glob(filepath.Join(Dir.Key, "*"+EXT_KEY))
		if err != nil {
			log.Fatal(err)
		}
		printCert(match)
	}
}
开发者ID:kless,项目名称:easycert,代码行数:29,代码来源:cmd_ls.go

示例11: SendMails

func SendMails(spool string, ss *Settings) {
	ecnt := 0
	files, err := filepath.Glob(spool + "/*.*")
	if err == nil {
		for _, f := range files {
			fn := path.Base(f)
			if strings.HasSuffix(f, ".env") {
				p := strings.Split(fn, "@")
				p = strings.Split(p[0], ".")
				ts, err := strconv.ParseInt(p[0], 36, 64)
				if err == nil {
					if ts+int64(ss.expire) <= time.Now().Unix() {
						ss.Debugf("SendMail: removing obsolete envelope: " + fn)
						purgeMsg(f, ss)
					} else {
						ecnt++
						go sendMail(f, ss)
					}
				} else {
					ss.Logf("RUNERR: invalid envelope: %s", fn)
				}
			} else {
				env, _ := filepath.Glob(f[0:len(f)-4] + "@*.env")
				if len(env) == 0 {
					ss.Debugf("SendMail: removing obsolete message: " + fn)
					purgeMsg(f, ss)
				}
			}
		}
		ss.Debugf("SendMails: queued_messages=%v", ecnt)
	} else {
		ss.Logf("RUNERR: %v", err)
	}
}
开发者ID:xrfang,项目名称:mailing_list_daemon,代码行数:34,代码来源:mailer.go

示例12: migLanguage

func migLanguage(language string) {
	fmt.Println("Migrating!")

	path := filepath.Join(site.pagedir, language)
	templatepath := filepath.Join(site.templatedir, language)
	// err :=
	os.MkdirAll(path, 0755)
	os.MkdirAll(templatepath, 0755)
	// if err != nil {
	//     return err
	// }
	pages, _ := filepath.Glob(site.pagedir + "/*.html")
	for c := 1; c < len(pages); c++ {
		copyfile(pages[c], filepath.Join(path, strings.Split(pages[c], "/")[len(strings.Split(pages[c], "/"))-1]))
		move(pages[c], filepath.Join("archive", pages[c]))
	}

	templates, _ := filepath.Glob(site.templatedir + "/*.html")
	for c := 0; c < len(templates); c++ {
		copyfile(templates[c], filepath.Join(templatepath, strings.Split(templates[c], "/")[len(strings.Split(templates[c], "/"))-1]))
		move(templates[c], filepath.Join("archive", templates[c]))
	}

	cfg.Section("general").NewKey("multiple_language_support", "y")
	cfg.Section("general").NewKey("primary_language", language)
	cfg.Section("general").NewKey("languages", language)
	cfg.SaveTo("config.ini")
}
开发者ID:dbenoot,项目名称:stare,代码行数:28,代码来源:update.go

示例13: init

func init() {
	config.ReadConfigFile("settings.yaml")
	//TODO: Error Checking
	basePath, _ := config.GetString("TEMPLATES:BASE")
	layoutsPath, _ := config.GetString("TEMPLATES:LAYOUTS")
	partialsPath, _ := config.GetString("TEMPLATES:PARTIALS")

	dir, _ := os.Getwd()
	templatesPath = filepath.Join(dir, basePath)
	fmt.Printf("Processing templates in %s\n", templatesPath)

	if templates == nil {
		templates = make(map[string]*template.Template)
	}

	layouts, err := filepath.Glob(templatesPath + "/" + layoutsPath + "/*")
	if err != nil {
		log.Fatal(err)
	}

	partials, err := filepath.Glob(templatesPath + "/" + partialsPath + "/*")
	if err != nil {
		log.Fatal(err)
	}

	for _, layout := range layouts {
		files := append(partials, layout)
		templates[filepath.Base(layout)] = template.Must(template.ParseFiles(files...))
	}

	UserRepo = user.NewBaseUserRepository()
	if _, err := UserRepo.NewUser("jeff", "password"); err != nil {
		fmt.Println(err)
	}
}
开发者ID:archeious,项目名称:ARES,代码行数:35,代码来源:main.go

示例14: collectAssets

// collectAssets collects the assets with this extension under src
func collectAssets(src string, extensions []string) ([]string, error) {

	assets := []string{}

	// TODO: perhaps use filepath.Walk instead
	// filepath.Glob doesn't appear to support ** or {}
	// this should catch
	// src/app/images/img.png
	// src/app/assets/images/img.png
	// src/app/assets/images/group/img.png
	for _, e := range extensions {
		pattern := path.Join(src, "*/*/*."+e)
		files, err := filepath.Glob(pattern)
		if err != nil {
			return assets, err
		}
		assets = append(assets, files...)
		pattern = path.Join(src, "*/*/*/*."+e)
		files, err = filepath.Glob(pattern)
		if err != nil {
			return assets, err
		}
		assets = append(assets, files...)
		pattern = path.Join(src, "*/*/*/*/*."+e)
		files, err = filepath.Glob(pattern)
		if err != nil {
			return assets, err
		}
		assets = append(assets, files...)
	}

	return assets, nil

}
开发者ID:fragmenta,项目名称:assets,代码行数:35,代码来源:assets.go

示例15: BenchmarkComplexGolang

func BenchmarkComplexGolang(b *testing.B) {
	var buf bytes.Buffer

	funcMap := template.FuncMap{
		"safehtml": func(text string) template.HTML { return template.HTML(text) },
	}

	templates := make(map[string]*template.Template)
	templatesDir := "go/"

	layouts, err := filepath.Glob(templatesDir + "layout/*.tmpl")
	if err != nil {
		panic(err)
	}

	includes, err := filepath.Glob(templatesDir + "includes/*.tmpl")
	if err != nil {
		panic(err)
	}

	// Generate our templates map from our layouts/ and includes/ directories
	for _, layout := range layouts {
		files := append(includes, layout)
		templates[filepath.Base(layout)] = template.Must(template.New("").Funcs(funcMap).ParseFiles(files...))
	}
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		templates["index.tmpl"].ExecuteTemplate(&buf, "base", testComplexData)
	}
}
开发者ID:SlinSo,项目名称:goTemplateBenchmark,代码行数:31,代码来源:templates_complex_test.go


注:本文中的path/filepath.Glob函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。