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

[MacPerl] fileloop etc



Howdy, y'all! This is my first post to the MacPerl list. I hope to be
a useful contributor through the future. I use MacPerl to write
little one-shots for doing massive data aggregation in my
organization's source code.

I'm currently working on creating some interesting web-browser
scripts as well. But enough of that, here's my contribution. Let me
know if any of this seems wrong...

Philippe de Rochambeau asks:

>What is the equivalent in Perl of Frontier's fileloop command (this
>command loops through all the files in a particular folder)?

This one's not too hard. Something like this:

$basedir = #either hard-code if a one shot or use a choose dialog
opendir (DIRECTORY, $basedir) || die "Cannot open directory";
foreach $filename (sort readdir(DIRECTORY)) {
    #do something
}

>What is the easiest way to access a file's name and modify it (e.g.,
>shorten its name to 8 characters + 3 char. extension)?

# you'll probably need to change directories for this to work the
# way you really want it to, but...

foreach $filename (sort readdir(DIRECTORY) {
    # this is a dorky algorithm, but it's something. make it
worthwhile.
    $newtemp = substr($filename,0,8);
    $newname = $newtemp . "txt";
    rename ($filename, $newname) || die ("can't rename $filename");
}

Russell Mirabelli

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