Is there a file separator constant for a specific operating system


#1

Hi All,

I was trying to split a directory for path and filename in a code. Was not aware of existence of splitdir() method. So I wrote a code like:

rsplit(filepath, “/”, limit=2)[2] to get the filename. Julia didn’t seem to like it on the Windows platform breaking the build.

If there would have been a method like fileseparator() which would return “/” on Linux and “\” on Windows I could write the code as:

rsplit(filepath, fileseparator(), limit=2)[2]

This could give other flexibilities as well.

regards,

Sambit

Note: Some systems (like cygwin) develop normalized paths as well like:

  1. ‘/’ is the file separator in all platforms
  2. //< Drive Letter>/ for windows like drive letters on unix like platforms. like say //C/Windows/

#2

Have you seen dirname() and basename()?


#3

@sbromberger thanks for making me aware of these 2 functions. I guess all I needed was basename() only.


#4

(Actually, the undocumented internal constant Base.Filesystem.path_separator is exactly this. But you really shouldn’t need to use it, thanks to functions like joinpath, basename, dirname, splitdir, abspath, and so on.)