How to convert a UNIX path to a DOS path

A regular expression or some other method is required to convert a UNIX path to a DOS path.

I have

C:/My Document/Photo.gif

Need

C:\My Document\Photo.gif
+3
source share
5 answers

This is a regular expression

s/\//\\/g
+4
source
#!/usr/bin/perl

use strict; use warnings;
use File::Spec::Win32;

print File::Spec::Win32->canonpath('C:/My Document/Photo.gif'), "\n";
+8
source

-, , - cmd.exe; API Windows ( cmd.exe , ).

, :

my $file = "C:/My Documents/Photo.gif";
$file =~ s{/}{\\}g;
print "$file\n";
+2

/ \. , Windows.

+1

, tr :

tr!\\!/!;
-1

Source: https://habr.com/ru/post/1781561/


All Articles