How to get platform specific path separator?

How do I get platform specific file separator in gdscript?

Just use the forward slash everywhere.

1 Like

Modern Windows versions (at least since Vista/7) allow using / everywhere you could use \, so even if you copy-paste a path that contains forward slashes in Windows Explorer or other apps, Windows will be able to interpret it correctly.

This means you rarely need to display paths with backslashes, but if you really want to, you can do this:

var path = "C:/path/to/file.txt"
if OS.has_feature("windows"):
    path = path.replace("/", "\\")

Windows is the only OS that still uses backslashes by convention. All other platforms use forward slashes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.