Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileinfo expensive operation -- no path #41643

anborg opened this issue Sep 27, 2020 · 1 comment

fileinfo expensive operation -- no path #41643

anborg opened this issue Sep 27, 2020 · 1 comment


Copy link

@anborg anborg commented Sep 27, 2020

How can I avoid this struct?

Is there another info that has path in it, so I don't invent my own struct for basic functionalities?

type MyNonsenseWorkaroundFileInfo struct {
	path string
	info os.FileInfo

func filesMatch(conf FileProcessorConfig) (files []MyNonsenseWorkaroundFileInfo, err error) {
	matchGlob := conf.InputDir + conf.GlobPath //path.Join - Does not work for windows(see log snippet below), going back to +
	log.Println("Find match for:", matchGlob)
	// 2020/09/26 21:31:59 Find match for: C:\data\projects_go\go-mail\input/*556*.csv
	// 2020/09/26 21:31:59 FIle : C:\data\projects_go\go-mail\input/*556*.csv C:\data\projects_go\go-mail\input
	// 2020/09/26 21:31:59 FIle : C:\data\projects_go\go-mail\input/*556*.csv C:\data\projects_go\go-mail\input\input556.csv
	// 2020/09/26 21:31:59 []  <- hmm no files found! input566.csv must be found.

	// var files []os.FileInfo
	err = filepath.Walk(conf.InputDir,
		func(walkPath string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			// log.Println("File :", matchGlob, walkPath)
			if matched, _ := filepath.Match(matchGlob, walkPath); matched == true { //info.Mode().IsRegular()

				if isOlderThanSecs(info.ModTime(), conf.OlderThanSeconds) {
					log.Println("Match: ", walkPath)
				myNonsenseFinfoWithPath := MyNonsenseWorkaroundFileInfo{path: walkPath, info: info}
				files = append(files, myNonsenseFinfoWithPath) //fileInfo is expensive, just return and reuse
			} else {
				//fmt.Println("Skip: ", walkPath, info.Size())

			return nil
		}) //filewalk
Copy link

@ALTree ALTree commented Sep 27, 2020


the Go project does not use its bug tracker for general discussion or asking questions about the language. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.

Please see the Questions wiki page; it has a list of good places for asking questions. Thanks!

Closing here, since this is not a bug.

@ALTree ALTree closed this Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.