7

Are there any available option to get platform specific file separator in Rust?

There can be different platform specific separators:

let separator = "\\" // Could be this.
let separator2 = "/" // Could be this.
let separator3 = "//" // Could be this.

I am looking like something following:

let env_independent_seperator = env::separator()

Then it may be the usage can be follows:

let folder = "C\\Folder\\Path";
let env_independent_separator = env::separator() // Looking something like this
let file_name = "File.txt";
let full_path = folder+ env_independent_separator + file_name;

Are there any File::separator() in Rust?

Matthieu M.
  • 268,556
  • 42
  • 412
  • 681
Akiner Alkan
  • 5,023
  • 25
  • 58

1 Answers1

12

Instead of using custom operations with separator one should use Pathbuf or Path for this problem.

In case of platform specific separator one should use std::path::MAIN_SEPARATOR.

BallpointBen
  • 7,176
  • 1
  • 30
  • 53
Akiner Alkan
  • 5,023
  • 25
  • 58