H
Hike Mike
I am trying to read the contents of a directory path argument and make
a list of only the directories found in the path. I am only getting
'.' and '..' when using the -d test file operator on windows xp when
the path contains other directories besides.
I have a directory with contents:
I have cygwin installed on windows xp so don't be confused by unix
commands like 'ls';
U:\perl\foo>ls -al
total 1
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:39 .
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:42 ..
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:40 dir1
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:40 dir2
-rw-r--r-- 1 Michael mkpasswd 10 Jul 21 09:39 file1
I want to list only dir1 and dir2
when run my script in the parent directory from
U:\perl>.\synchDir.pl foo
the output is:
found directory: .
found directory: ..
but i think is should be:
found directory: .
found directory: ..
found directory: dir1
found directory: dir2
The code I wrote is:
__BEGIN__
#!/usr/bin/perl
use strict;
use warnings;
my $fromArg = $ARGV[0];
unless ($fromArg) {
die "must supply a source directory to synchronize from as first
argument\n";
}
opendir (FROMDIR, "$fromArg") or die "ummmm: $fromArg: $!\n";
while (my $file = readdir(FROMDIR)) {
next unless -d $file;
print "found directory: $file\n";
}
__END__
and the following change (to remove '.' and '.." from the list of
directories) yeilds no output:
__BEGIN__
while (my $file = grep !/^\./, readdir FROMDIR) {
next unless -d $file;
print "found directory: $file\n";
}
__END__
a list of only the directories found in the path. I am only getting
'.' and '..' when using the -d test file operator on windows xp when
the path contains other directories besides.
I have a directory with contents:
I have cygwin installed on windows xp so don't be confused by unix
commands like 'ls';
U:\perl\foo>ls -al
total 1
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:39 .
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:42 ..
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:40 dir1
drwxr-xr-x 1 Michael mkpasswd 0 Jul 21 09:40 dir2
-rw-r--r-- 1 Michael mkpasswd 10 Jul 21 09:39 file1
I want to list only dir1 and dir2
when run my script in the parent directory from
U:\perl>.\synchDir.pl foo
the output is:
found directory: .
found directory: ..
but i think is should be:
found directory: .
found directory: ..
found directory: dir1
found directory: dir2
The code I wrote is:
__BEGIN__
#!/usr/bin/perl
use strict;
use warnings;
my $fromArg = $ARGV[0];
unless ($fromArg) {
die "must supply a source directory to synchronize from as first
argument\n";
}
opendir (FROMDIR, "$fromArg") or die "ummmm: $fromArg: $!\n";
while (my $file = readdir(FROMDIR)) {
next unless -d $file;
print "found directory: $file\n";
}
__END__
and the following change (to remove '.' and '.." from the list of
directories) yeilds no output:
__BEGIN__
while (my $file = grep !/^\./, readdir FROMDIR) {
next unless -d $file;
print "found directory: $file\n";
}
__END__