in reply to Re: how to dir a directory that have space
in thread how to dir a directory that have space

From cmd need to put "" but when i put " in script it just hang and does not give any response.

dir E:\common\compare\"latest folder"\PDF\DB\

this is what i tried but it just stall when perform dir

my $source_directory = 'E:\\common\compare\"latest folder"\PDF\DB\\'; `dir $source_directory /b/s /o:-d`;

Replies are listed 'Best First'.
Re^3: how to dir a directory that have space
by Discipulus (Canon) on Jan 16, 2015 at 08:56 UTC
    Hello AtlasFlame,

    here you are mixing two problems: path with spaces AND path separator.
    With ugly path with spaces you need double quotes around the whole path:
    dir "C:\Local Publish\images" #OK
    So if you need to pass such a string with doublequotes untouched, for example inside a sigle quote string you need to escape (with '\') all occourences of " you want to be passed unaltered, as in:
    perl -e " $dir = '\"C:\Local Publish\images\"'; system qq(dir $dir )" + #OK
    As personal suggestion avoid to create and use paths with spaces, is a very stupid 'feature'.

    Now the path separator part. As far as i know, you can use both '\' and '/' as path separator in windows. This is handy because the '\' happens to be the escape char in Perl. In the command prompt you can safely use:
    dir "C:/Local Publish/images" #OK
    So you can safely do the same in a Perl program:
    perl -e " $dir = '\"C:/Local Publish/images\"'; system qq(dir $dir )" + #ok
    If you need to interpolate some var inside such strings you need the concatenation operator (the dot '.'):
    perl -e " $img = 'images';$dir = '\"C:/Local Publish/'.$img.'\"'; syst +em qq(dir $dir )"
    You can use this post as explaination of quotes in Perl and the docs as base rference. Read also the usage hints on windows especially using Perl from command line.

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      As personal suggestion avoid to create and use paths with spaces, is a very stupid 'feature'.
      I disagree, this is a perfectly normal and good feature, what is stupid is cmd.exe and various clones of sh. I avoid using them and use normal programming languages instead, such as Perl.
        Ok you are right Anon ;=)
        it would be better stated as: "try to avoid paths with spaces if you want avoid the stupidness of cmd.exe"
        L*
        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^3: how to dir a directory that have space
by Anonymous Monk on Jan 16, 2015 at 04:23 UTC