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

Re: [MacPerl] a little help



At 11.09 1/2/98, PETER@yalevm.ycc.yale.edu wrote:
>Hi.  Can someone show me a bit of code that would split up a Macintosh
>folder that has thousands of files in it, into lots of individual folders
>that have only a 100 files each?  In other words, one folder with 1000
>items would become 10 folders with 100 items each.  I would be very
>grateful for any assistance.  Thanks in advance.  Yes, I'm new to
>Perl/MacPerl.  - peter

#!perl -w
use strict;
my($count, $count2, $dir, $dir2, $file, $num);
$count = $count2 = 0;
$num   = 100;
$dir   = 'PowerPudgeII:Desktop Folder:mydir';
$dir2  = "$dir:new$count";

mkdir($dir2, 0) || die($!);

opendir(D, $dir) || die($!);
foreach $file(sort readdir(D)) {
  rename "$dir:$file", "$dir2:$file";

  if (++$count2 >= $num) {
    $count2 = 0;
    $count++;
    $dir2 = "$dir:new$count";
    mkdir($dir2, 0) || die($!);
  }

}

--
Chris Nandor               pudge@pobox.com           http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==                    MacPerl: Power and Ease                     ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#



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