You can't do that with the filepath.Join()
as its documentation states:
Join calls Clean on the result...
And since .
denotes the "current" directory, it will be removed by filepath.Clean()
:
It applies the following rules iteratively until no further processing can be done:
[...]
Eliminate each . path name element (the current directory).
And in fact you can't do what you want with the path/filepath
package at all, there is no support for this operation.
You need to use string concatenation manually. Use filepath.Separator
for it, it'll be safe:
x := filepath.Join("home", "my_name", "need_folder") +
string(filepath.Separator) + "."
fmt.Println(x)
Output (try it on the Go Playground):
home/my_name/need_folder/.