Perl opendir with spaces in directory names

Discussion in 'Perl Misc' started by JJ, Nov 24, 2004.

  1. JJ

    JJ Guest

    Hi all,

    I'm using opendir(dirhandle, expr), but perl seems te be unable to open the
    dir specified in the expr. My expression is "C:\\My Documents\\My
    Pictures\\". When I use C:\\Windows\\System32\\ it works fine, but I guess
    spaces aren't alowed here. How can I solve this problem without renaming my
    directory?

    Thanks, Vincent
    JJ, Nov 24, 2004
    #1
    1. Advertising

  2. JJ

    mothra Guest

    "JJ" <> wrote in message
    news:41a4c478$0$44094$...
    > Hi all,
    >
    > I'm using opendir(dirhandle, expr), but perl seems te be unable to open

    the
    > dir specified in the expr. My expression is "C:\\My Documents\\My
    > Pictures\\". When I use C:\\Windows\\System32\\ it works fine, but I guess
    > spaces aren't alowed here. How can I solve this problem without renaming

    my
    > directory?
    >
    > Thanks, Vincent
    >

    Works for me !!

    use strict;
    use warnings;

    opendir (IN, "c:/documents and settings") or die "Can't open dir:$!\n";

    while (defined ( my $filename = readdir(IN) ) ) {
    print $filename, "\n";
    }

    output:F:\scripts>test.pl
    ..
    ...
    Administrator
    All Users
    Default User
    test
    ugplot

    Hope this helps

    Mothra


    Hope this helps
    mothra, Nov 24, 2004
    #2
    1. Advertising

  3. JJ

    John Bokma Guest

    JJ wrote:

    > Hi all,
    >
    > I'm using opendir(dirhandle, expr), but perl seems te be unable to
    > open the dir specified in the expr. My expression is "C:\\My
    > Documents\\My Pictures\\". When I use C:\\Windows\\System32\\ it works
    > fine, but I guess spaces aren't alowed here. How can I solve this
    > problem without renaming my directory?
    >
    > Thanks, Vincent


    use strict;
    use warnings;

    my $dir = 'C:\Documents and Settings\John\Mis documentos\Mis imágenes';

    opendir my $dh, $dir or die "Can't opendir '$dir': $!";
    my @jpg = grep /\.jpe?g$/i, readdir $dh;
    closedir $dh or die "Can't closedir '$dir': $!";

    print join "" => map { "$_\n" } @jpg;


    000_0946.JPG
    000_0947.JPG
    000_0948.JPG
    000_1019.JPG
    :
    :


    Note that you can use / instead of \.

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, Nov 24, 2004
    #3
  4. JJ wrote:
    > Hi all,
    >
    > I'm using opendir(dirhandle, expr), but perl seems te be unable to openthe
    > dir specified in the expr. My expression is "C:\\My Documents\\My
    > Pictures\\". When I use C:\\Windows\\System32\\ it works fine, but I guess
    > spaces aren't alowed here. How can I solve this problem without renaming my
    > directory?


    What error message do you get ($!)?

    I checked on a W2k machine and there wasn't a "C:\My Documents" folder,
    there was a "C:\Documents and Settings\josef\My Documents\My Pictures",
    though.

    (Blimey! Here I am, answering a Windows question, maybe even answering
    it. Sure hope no colleague reads this. B-{)
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
    Josef Moellers, Nov 25, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. fBechmann
    Replies:
    0
    Views:
    399
    fBechmann
    Jun 10, 2004
  2. rtilley
    Replies:
    22
    Views:
    660
    Christos Georgiou
    Mar 2, 2006
  3. Daniel Berger
    Replies:
    5
    Views:
    301
  4. Mike
    Replies:
    16
    Views:
    445
    Joe Smith
    Jan 19, 2004
  5. theo22
    Replies:
    12
    Views:
    390
    Anno Siegel
    Jan 21, 2004
Loading...

Share This Page