2 releases

0.0.2 Sep 16, 2021
0.0.1 Sep 15, 2021

#913 in Filesystem

Download history 593/week @ 2024-07-21 95/week @ 2024-07-28 302/week @ 2024-08-04 253/week @ 2024-08-11 359/week @ 2024-08-18 283/week @ 2024-08-25 257/week @ 2024-09-01 326/week @ 2024-09-08 336/week @ 2024-09-15 683/week @ 2024-09-22 530/week @ 2024-09-29 497/week @ 2024-10-06 367/week @ 2024-10-13 1020/week @ 2024-10-20 934/week @ 2024-10-27 1203/week @ 2024-11-03

3,524 downloads per month
Used in wsl-dirutils

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