toLocalPath method
Convert a Windows path to a WSL local path.
Implementation
String toLocalPath(String windowsPath) {
// Handle UNC paths for WSL (\\wsl$\distro\...)
final wslUncMatch = RegExp(
r'^\\\\wsl\$\\([^\\]+)\\(.*)$',
caseSensitive: false,
).firstMatch(windowsPath);
if (wslUncMatch != null) {
final path = wslUncMatch.group(2)!.replaceAll('\\', '/');
return '/$path';
}
// Handle \\wsl.localhost\ paths
final wslLocalhostMatch = RegExp(
r'^\\\\wsl\.localhost\\([^\\]+)\\(.*)$',
caseSensitive: false,
).firstMatch(windowsPath);
if (wslLocalhostMatch != null) {
final path = wslLocalhostMatch.group(2)!.replaceAll('\\', '/');
return '/$path';
}
// Handle standard Windows drive paths (C:\Users\...)
final driveMatch = RegExp(r'^([a-zA-Z]):\\(.*)$').firstMatch(windowsPath);
if (driveMatch != null) {
final drive = driveMatch.group(1)!.toLowerCase();
final path = driveMatch.group(2)!.replaceAll('\\', '/');
return '/mnt/$drive/$path';
}
return windowsPath;
}