2 releases

0.0.2 Sep 16, 2021
0.0.1 Sep 15, 2021

#894 in Filesystem

Download history 1817/week @ 2024-11-15 1885/week @ 2024-11-22 1856/week @ 2024-11-29 2719/week @ 2024-12-06 1711/week @ 2024-12-13 394/week @ 2024-12-20 172/week @ 2024-12-27 1336/week @ 2025-01-03 1988/week @ 2025-01-10 2111/week @ 2025-01-17 2191/week @ 2025-01-24 2465/week @ 2025-01-31 1756/week @ 2025-02-07 1674/week @ 2025-02-14 1740/week @ 2025-02-21 1817/week @ 2025-02-28

7,472 downloads per month
Used in 10 crates (2 directly)

MIT license

6KB
58 lines

WSL Path

You can use WSLPath to convert a WSL Path to a Windows Path and vice versa


Implementation

Calls wslpath which is a Linux based utility created by Microsoft to convert Windows and Linux paths.

We call wslpath, pass arguments, perform a conversion and return the results to the user


Converting Windows Path to WSL Path

fn main() {
	let path = wslpath::windows_to_wsl("C:\\Users").unwrap();
	println!("Windows Path converted to WSL is {}",path);
}

OUTPUT

Windows Path converted to WSL is /mnt/c/Users


Converting WSL Path to Windows Path

fn main() {
	let path = wslpath::wsl_to_windows("/mnt/c/Users").unwrap();
	println!("WSL Path converted to Windows is {}",path);
}

OUTPUT

WSL Path converted to Windows is C:/Users


Converting Windows Path to WSL Path with a specific distro

In this case we are using Ubuntu

fn main() {
    let path = wslpath::windows_to_wsl_with_distro("C:\\Users", "Ubuntu".to_string()).unwrap();
    println!("Windows Path converted to WSL is {}", path);
}

OUTPUT

Windows Path converted to WSL is /mnt/c/Users


Converting WSL Path to Windows Path with a specific distro

In this case we are using Ubuntu

fn main() {
    let path = wslpath::wsl_to_windows_with_distro("/mnt/c/Users", "Ubuntu".to_string()).unwrap();
    println!("WSL Path converted to Windows is {}", path);
}

OUTPUT

WSL Path converted to Windows is C:/Users


No runtime deps