# Is there a file separator constant for a specific operating system

**URL:** <https://discourse.julialang.org/t/is-there-a-file-separator-constant-for-a-specific-operating-system/5104>\
**Category:** General Usage\
**Created:** [July 28, 2017, 9:18am UTC](https://discourse.julialang.org/t/is-there-a-file-separator-constant-for-a-specific-operating-system/5104 "2017-07-28T09:18:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)\
**Post date:** [July 28, 2017, 9:18am UTC](https://discourse.julialang.org/t/is-there-a-file-separator-constant-for-a-specific-operating-system/5104/1 "2017-07-28T09:18:05Z")

</div>

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/

---

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [July 28, 2017, 5:06pm UTC](https://discourse.julialang.org/t/is-there-a-file-separator-constant-for-a-specific-operating-system/5104/2 "2017-07-28T17:06:46Z")

</div>

Have you seen `dirname()` and `basename()`?

---

<div class="post-metadata">

**Author:** ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)\
**Post date:** [July 28, 2017, 5:48pm UTC](https://discourse.julialang.org/t/is-there-a-file-separator-constant-for-a-specific-operating-system/5104/3 "2017-07-28T17:48:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 29, 2017, 2:04am UTC](https://discourse.julialang.org/t/is-there-a-file-separator-constant-for-a-specific-operating-system/5104/4 "2017-07-29T02:04:26Z")

</div>

> [@sambitdash](#):
>
> If there would have been a method like `fileseparator()` which would return “/” on Linux and “\” on Windows

(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.)
