Crates.io | wslpath2 |
lib.rs | wslpath2 |
version | 0.1.3 |
source | src |
created_at | 2023-03-04 19:57:04.497102 |
updated_at | 2024-10-20 15:25:13.438541 |
description | Convert Windows to WSL paths and vice-versa |
homepage | https://github.com/michidk/wslpath2 |
repository | https://github.com/michidk/wslpath2 |
max_upload_size | |
id | 800797 |
size | 10,994 |
You can use wslpath2
to convert a WSL Path to a Windows Path and vice versa.
Internally it calls the wslpath
utility, which is a Linux-based utility created by Microsoft to convert Windows and Linux paths. This is called through the WSL command, so that it works on Linux (from within the WSL) as well on Windows.
This is a fork of wslpath by pratikpc with the following changes:
wslpath.exe
's command line argumentswslpath.exe
The main function is convert
which has the following signature:
pub fn convert(
path: &str,
distro: Option<&str>,
options: Conversion,
force_absolute_path: bool,
) -> Result<String, Box<dyn std::error::Error>>
Usage example:
// Convert WSL path to Windows
let path = convert("/mnt/c/Users", None, Conversion::WslToWindows, false).unwrap();
println!("WSL Path converted to Windows is {}", path);
// OUTPUT is WSL Path converted to Windows is C:\Users
// Convert Windows path to WSL
let path = convert("C:\\Users", None, Conversion::WindowsToWsl, false).unwrap();
println!("Windows Path converted to WSL is {}", path);
// OUTPUT is Windows Path converted to WSL is /mnt/c/Users
Also, see the examples folder for more examples.