2 releases

0.0.2 Sep 16, 2021
0.0.1 Sep 15, 2021

#926 in Filesystem

Download history 105/week @ 2024-03-12 35/week @ 2024-03-19 46/week @ 2024-03-26 76/week @ 2024-04-02 44/week @ 2024-04-09 33/week @ 2024-04-16 59/week @ 2024-04-23 43/week @ 2024-04-30 65/week @ 2024-05-07 34/week @ 2024-05-14 20/week @ 2024-05-21 22/week @ 2024-05-28 19/week @ 2024-06-04 23/week @ 2024-06-11 33/week @ 2024-06-18 14/week @ 2024-06-25

91 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