Should the return value of System.tmp_dir/0 always have a slash at end?

I save a temp file with System.tmp_dir() <> path. In macOS, the tmp_dir is something like /var/folders/97/wznf75697jgbhl61rg5wj0pr0000gn/T/ while in Linux it is /tmp, missing the slash at the end.

Shall we always ensure a slash at the end or does it design by purpose?


1 Like

You shall not do System.tmp_dir <> path but instead do Path.join(System.tmp_dir, path), then the trailing slash becomes irrelevant.


Thanks, that’s the solution.

But why not ensure a slash at end?

Because it doesn’t matter, you should always use Path.join/1,2. Not all OS’s use the same slash, not even all OS’s use any slash at all (didn’t beOS use : or something, and there are others too).

If I were to make the BEAM interfaces from scratch I absolutely would have a path be {:path, "binary"} instead of just a plain binary.


Thank you, that’s the point.