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?
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.
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.
Path separators are the characters (semicolons on Windows, colons on Unix) that separate individual elements of a value that represents multiple paths.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With