Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the file path separator for the current platform?

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?

like image 961
Akiner Alkan Avatar asked Jan 10 '19 12:01

Akiner Alkan


People also ask

What is file path separator?

pathSeparator is used to separate individual file paths in a list of file paths. Consider on windows, the PATH environment variable. You use a ; to separate the file paths so on Windows File. pathSeparator would be ; . File.

What is path separator in Java?

pathSeparator: Platform dependent variable for path-separator. For example PATH or CLASSPATH variable list of paths separated by ':' in Unix systems and ';' in Windows system. File. pathSeparatorChar: Same as pathSeparator but it's char.

What is path separator in Linux?

Path separators are the characters (semicolons on Windows, colons on Unix) that separate individual elements of a value that represents multiple paths.


1 Answers

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

  • Path.join
  • Pathbuf.push

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

like image 154
Akiner Alkan Avatar answered Oct 14 '22 06:10

Akiner Alkan