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

paths.Join & path.Match not working for windows paths? #41644

Closed
anborg opened this issue Sep 27, 2020 · 1 comment
Closed

paths.Join & path.Match not working for windows paths? #41644

anborg opened this issue Sep 27, 2020 · 1 comment

Comments

@anborg
Copy link

@anborg anborg commented Sep 27, 2020

path.Join - not joining in a manner where path.Match can return correct results.

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.

'''golang
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, _ := path.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
return

}'''

Expectation :

Path match should work in windows if the paths are provided in these formats

Config1.yml

fileProcessor:
    globPath: "*556*.csv"
    olderThanSeconds: 2
    inputDir : "C:\\data\\projects_go\\go-mail\\input\\" <- ugly, not redable, other languages java/python support usage of c:/data/projects_go/...

Config1.yml - path.Join must include missing slash "/" or "\", and path.Match must be able to find the pattern in windows.

fileProcessor:
    globPath: "*556*.csv"
    olderThanSeconds: 2
    inputDir : "C:/data/projects_go/go-mail/input"
@davecheney
Copy link
Contributor

@davecheney davecheney commented Sep 27, 2020

Use the path/filepath package

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@davecheney davecheney closed this Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
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.