首页 > 解决方案 > 在路径变量名称中保留空格

问题描述

我想打开一个剪辑目录。在目录路径中,中间有空格。路径存储在$pathg变量中。

请告诉我如何打开路径或如何使用路径变量在路径中添加转义字符?

Path = \\fmsgfxauto4\mediatests$\ATS-MediaTests\Tests\Media\Video\Decoder-Streams\AVC\Suite\VClips\Main_Profile\VC-303-A D-Traffic-AVC-MP\FunctionalTests\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6

代码:

        opendir (CLIPDIR, $pathg) or die "Couldn't open directory $pathg, $!";
        my $isfound = 0;
        while (my $clip = readdir CLIPDIR and $pathg)
        {
            #if($clip =~ /.264$/)
            if(grep{/.264$/ || /.avc$/ || /.26l$/} "$clip")
            {   

标签: perltypescript

解决方案


在双引号字符串文字中,存在\$需要转义的字符。

my $pathg = "\\\\fmsgfxauto4\\mediatests\$\\ATS-MediaTests\\Tests\\Media\\Video\\Decoder-Streams\\AVC\\Suite\\VClips\\Main_Profile\\VC-303-A D-Traffic-AVC-MP\\FunctionalTests\\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6";

在单引号字符串文字中,存在的字符\可能会被转义,但只有在后面跟着另一个\.

my $pathg = '\\\\fmsgfxauto4\\mediatests$\\ATS-MediaTests\\Tests\\Media\\Video\\Decoder-Streams\\AVC\\Suite\\VClips\\Main_Profile\\VC-303-A D-Traffic-AVC-MP\\FunctionalTests\\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6';

或者

my $pathg = '\\\fmsgfxauto4\mediatests$\ATS-MediaTests\Tests\Media\Video\Decoder-Streams\AVC\\Suite\VClips\Main_Profile\VC-303-A D-Traffic-AVC-MP\FunctionalTests\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6';

推荐阅读