I have a program in which I use a lot "../" which is to go one level up in the file system and run some process on the directory with specific name. I have a command line tool in Go.
I have 3 questions
- there is nicer way to do it instead of “../“
- is there a const with which I can use instead of “/“
- if 2 is not available should I create “constants“ under that internal package to share the “/“ between packages since I need it in many place (from diff packages...)
example
dir.zip("../"+tmpDirName, "../"+m.Id+".zip", "../"+tmpDirName)
Set a variable, and use that everywhere:
path := "../"
or
path := ".." + string(os.PathSeparator)
then later:
dir.zip(path+tmpDirName, path+m.Id+".zip", path+tmpDirName)
This makes it very easy to change the path in the future, via a command line option, configuration, or just editing the value.
Yes. os.PathSeparator is the OS-specific path separator for the current architecture.
filepath.Join("..", someDir, someFilename)