thebourneid
thebourneid

Reputation: 113

Perl File::Find Windows Backslashes Directory Path

Is there an easy way to automatically replace the $dir backslashes with forward ones because the only way I know is manually and if the path is too long is quite annoying. Thanks.

use strict; 
use warnings;
use File::Find;

my $dir = "E:\dir1\dir2\dir3\dir4\dir5";

find(\&temp, $dir);
sub temp {
    .....
}

Upvotes: 1

Views: 2960

Answers (2)

czubatka
czubatka

Reputation: 61

What about idea of non system dependent path? There is module called File::Spec in the standard perl distribution. Look at this code:

use strict;
use warnings;

use File::Spec;

my $path;
$path = File::Spec->catfile("dir1","dir2","dir3","dir4","dir5");

Upvotes: 1

TLP
TLP

Reputation: 67908

Not quite sure what you are after, but a simple regex will suffice to replace \ with /:

ETA: You will have to place the paths in single quotes to preserve the backslashes, then replace them (thanks cjm for pointing that out):

$dir = 'E:\dir1\dir2\dir3\dir4\dir5';
$dir =~ s#\\#/#g;

Upvotes: 2

Related Questions