Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open a data file in the same directory as the current file
_, filename, _, _ := runtime.Caller(1)
f, err := os.Open(path.Join(path.Dir(filename), "data.csv"))
@vhmth

This comment has been minimized.

Copy link

commented Sep 16, 2014

Just a head's up that this may not be portable:

https://groups.google.com/forum/#!topic/golang-nuts/XiKfqDO3rKQ

@Thomasdezeeuw

This comment has been minimized.

Copy link

commented Jul 20, 2015

Another head's up, this checks which function called the current function (which calls runetime.Caller). You need to use runtime.Caller(0) to get the current function's filepath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.