[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Folder recursion and recognition problem



I've been using both the DOS and Mac ports of PERL and am having trouble
with folder recursion and folder recognition on the Mac.

I want to be able to drag and drop a disk onto a MacPerl droplet and have
the droplet evaluate every file and folder on the disk.

Here are my problems so far. (The MacPerl script follows after):

- When the droplet is on the desktop of my Mac, and i drop a disk onto it,
the droplet thinks the folders on the disk are files, not folders, and so
doesn't open them to see if any files are contained in them. (I'm using the
"if -d" test to see if they are folders.)

- When i put the droplet _onto_ the disk and then launch it from there, it
works ok, unless a file _within_ a folder has the same name as the
containing folder itself (i.e., FOLDER name: FIG 28.01. FILE name within
folder: FIG 28.01. In that case, the droplet gets confused and gets stuck on
the folder (or file, thinking the file is a folder?). When i say "Get's
stuck", it just keeps going over and over the folder without procesing its
contents. As soon as i change (for testing purposes) the file name within
the folder to be something different from the containing folder, the script
progresses smoothly.

I have a feeling it's something quite basic staring me in the face but i'm
just not seeing it. If anyone can point me to a source, or can spot the
problem, that would be great.

TIA for any help.

Ben

==========
MACPERL SCRIPT FOLLOWS:

sub folderwalk {
 local(@files); # declare variable local
 local($dir)=$_[0]; # $_[0] is argument passed in calling the subroutine
 opendir(DIR,"$dir")||die "couldn't open DIR $dir\n";
 @files=readdir(DIR); # read files into an array
 close(DIR);

 @files=sort(@files); # sort the list of files in $dir
 $numfiles=@files;       #get the number of files
 print "there are $numfiles files/directories in the root of this directory
named $dir\n";
 foreach (@files){
  if (-d $_) { # if file is a directory
   print "$_ is a DIRECTORY!\n";
   &folderwalk($_);
  }else{
   print "file only $_\n";
  }
 }
} # end of subroutine definition

&folderwalk($ARGV[0]);    # assumes only disk dropped on droplet