#path #wsl #convert #windows

wslpath2

Convert Windows to WSL paths and vice-versa

4 releases

0.1.3 Oct 20, 2024
0.1.2 Sep 14, 2024
0.1.1 Mar 5, 2023
0.1.0 Mar 4, 2023
0.0.1 Mar 4, 2023

#373 in Filesystem

Download history 9/week @ 2024-07-29 14/week @ 2024-08-05 138/week @ 2024-09-09 70/week @ 2024-09-16 22/week @ 2024-09-23 42/week @ 2024-09-30 119/week @ 2024-10-14 57/week @ 2024-10-21 4/week @ 2024-10-28 6/week @ 2024-11-04 16/week @ 2024-11-11

194 downloads per month
Used in vscli

MIT license

8KB
94 lines

wslpath2

MIT License Crates.io rust docs Continuous integration

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.

About this fork

This is a fork of wslpath by pratikpc with the following changes:

  • Uses Rust 2021 edition
  • Adds settings enum to closely map to wslpath.exe's command line arguments
  • Updated to the newest version of wslpath.exe
  • Error handling is improved

Usage

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.

No runtime deps