开发者

Perl File::Find Windows Backslashes Directory Path

Is there an easy way to automatically replace the $dir backslashes with forward o开发者_开发百科nes 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 {
    .....
}


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;


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜