Dennis wrote:
>> The script has a problem when it hits a directory or filename containing
>> spaces.

"Sisyphus" <[EMAIL PROTECTED]> said:

> Probably best if you could provide a small standalone
> script (or one liner) that we can all run, and that
> demonstrates the problem.

Once I've created a test script based on my code, the test script
runs just fine! My problem must be at some other place. I'll
be tracking that down.

I'll paste a full copy of the test script I based on the original code.
I'll post it here, since it has been so damned useful, people might
want to use it. The recursive subroutine calls two callbacks, and
you can do all sorts of useful things in whatever callbacks you
point to. I have a number of scripts based on dir_walk (Thank you,
MJD!)

################
#! -perl-

use strict;
use warnings;

system('cls');

################ Set variables
my $toplevel = 'C:\PROJECTS\ACTIVE\R1.4\r1.4 Hotfixes';

my %the = ('debug' => 1);
my $the = \%the;

################ Call main subroutine.

print "Executing $0)\n";
&dir_walk ( "$toplevel", \&print_file, \&print_dir );

exit;

################

=head2 print_file

First callback

=cut

sub print_file {
 print "File: ", $_[0] , "\n";
}
################

=head2 print_file

Second callback

=cut

sub print_dir {
 print "Directory: ", $_[0] , "\n";
 return;
}
################

=head2 dir_walk

This is the heart of the application. The routine
walks a directory tree located at some path,
supplied in argument $top

$filefunc and $dirfunc are two callbacks, supplied
as subroutine references

=cut

sub dir_walk {
  my ($top, $filefunc, $dirfunc) = @_;
  my $DIR;,

  print "In sub dir_walk\n" if $the->{debug} == 1;
  print "top: $top\n" if $the->{debug} == 1;

  if ( -d $top ) {
    print "toplevel is a DIR; opendir it\n" if $the->{debug} == 1;
    my $file;
    unless (opendir $DIR, $top) {
      warn "Couldn't open directory $top: $!; skipping.\n";}
      return;
    }

    my @results;
    FILE:
    while ($file = readdir $DIR) {
      next FILE if $file eq '.' || $file eq '..';
      print "File: $file\n" if $the->{debug} == 1;
      push @results, dir_walk("$top/$file", $filefunc, $dirfunc);;
    }

    return $dirfunc->($top, @results);

  } else {

    print "flag -d did not detect a dir: $top \n" if $the->{debug} == 1;

    return $filefunc->($top);
  }
}
################

best,

 /dennis

------------------------------------------------
Dennis Daupert, PhD
Senior Systems Development Professional -- CSC Account
CSC

GOS | o: 1.317.298.9499 | [EMAIL PROTECTED] | www.csc.com

This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery.
NOTE: Regardless of content, this e-mail shall not operate to bind CSC to
any order or other contract unless pursuant to explicit written agreement
or government initiative expressly permitting the use of e-mail for such
purpose.

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to