Perl opendir with spaces in directory names

J

JJ

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
 
M

mothra

JJ said:
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
 
J

John Bokma

JJ said:
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 \.
 
J

Josef Moellers

JJ said:
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-{)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top