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

Re: [MacPerl] MAC Filesystem Help



Maybe I'm missing something obvious here, but what's wrong with:

#!perl
while (@ARGV) {
   my $arg = shift;
   process( $arg );        
}

sub process ($) {
   my $fn = shift;
   if ( -d $fn ) {
	       local *D;
        opendir D, $fn or die "Couldn't open dir $fn; $!";
        while ( my $file = readdir D ) {
             process( "$fn:$file" ) ;
        }
   }
   else {
      open F, $fn or die "Couldn't open $fn; $!";
      print ++$argnr, ": $fn\n"; # or process as you like
      close F;
   }
}

Save it as a droplet, and drop your "Frads" folder on it.  Seems a lot 
simpler than messing with file system calls -- either directly or via
a module.

>I need to convert the following DOS-Perl fragment to run on a MAC.
>----------------------------------------------------------------------
># temporary file which contains the name of all files in "Frads"
>system("ls c:/\Frads > temp"); # this needs to be converted to MAC

>
># open filehandle called "temp"
>open(temp,"temp"); 
>
># read each file name 1 by 1
>while ($direct = <temp>) {
>
>	# create path to file
>	$fname = "c:\\Frads\\" . "$direct"; # convert to MAC
>	
>	# open filehandle to current file
>	open(input,"$fname");
>-----------------------------------------------------------------------	
>	
>On the MAC I have a folder on the Desktop called "Frads" and this folder 
>contains many (probably about 50) files. I want to open each file 1 by
>1 (using a while statement as above) and then operate on the file. I guess 
>the
>main help I need is figuring out how to access the MAC file system so 
>I can open each file in the "Frads" folder 1 by 1. I think this should be 
>very
>easy for anyone who has experience using MAC-perl.
>
>
>						Thanks,
>						Ameet

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch