I want to add the GetFileTime Windows function to the syscall package. I see that the SetFileTime function is already defined in https://github.com/golang/go/blob/master/src/syscall/zsyscall_windows.go, but not GetFileTime. I can see that that file is generated by go generate but I don’t know how it’s generated (maybe by the lines prefixed with //sys starting on line 139 of syscall_windows.go?). How do I find that out so that I can create a proper pull request?
Why?
I wrote a program last week where I need to essentially grep exact positions within thousands of files spread across tens or hundreds folders throughout a dozen Windows network shares. The Windows findstr command and grep under Cygwin both worked but I needed to only include results from files created within a certain date range. The existing os.FileInfo.ModTime is not sufficient because it’s the creation time that I needed.
Workaround
I have a package on GitHub: github.com/skillian/getfiletime that exports a GetFileTime function which returns a struct of the CreationTime, LastAccessTime and LastWriteTime of a file, all as time.Time structs that currently satisfies my needs, but I think the syscall.SetFileTime should have its syscall.GetFileTime compliment.
EDIT: preformatted os.FileInfo.ModTime EDIT #2: added my workaround
Thanks for your reply, nfuhs. I have an implementation here: https://github.com/skillian/getfiletime that satisfies my current needs, but what I want to try to do is get the GetFileTime syscall into the Windows syscall package to compliment the SetFileTime call that’s already present.
I signed up to contribute to Go, but when I went to open an issue, I got this message:
Before you open an issue please review the support and contributing guidelines for this repository.
I don’t really understand how to use mailing lists, so I followed the second bullet point and came here! It seems now like I should go ahead and post the issue on GitHub.
I’ll keep this post open until after I figure out how changes to syscall_windows.go (or wherever else I need to add Windows API syscall functions) are added and then I’ll update this thread and close it.
I’m not sure that there is an error with the way things presently work. Doing a quick bit of googling has shown that you can get these properties from syscall as it is already. Here is a link to a repository that does this already( check out the ctime_windows.go file for how: https://github.com/djherbis/times
I don’t exactly think there’s a problem with the way things work just an asymmetry that became a problem for me because I was looking for the “other half.” I thought it would be a good idea to contribute a function definition to the Golang standard library once a use case arose.
Believe it or not, I did do a bit of Googling before posting but in retrospect, I think I had tunnel vision and was looking only for an implementation of the Windows GetFileTime. For my future projects, I definitely think I’ll be using Dustin’s times package; thanks for the suggestion.