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

Re: [MacPerl] PC file names



Chris Nandor writes Fri, 13 Feb 1998 15:52:15 -0500
>I have a PPC 604e/180, PC Exchange (without which I could not mount said PC
>floppy), and I can directly access a file on the floppy with MacPerl (I
>read its contents and print them out), but I cannot read the directory of
>said floppy with MacPerl (opendir() does not fail, but readdir() returns
>nothing).
>
>Anyone know the answer to this?

I have tried some experiments today with some mixed results. I had a set of
PC discs (British Airways time-tables) and a PC CD catalogue (Farnell
electronic components).

I have a Powerbook 68030/MacOC 7.5.1/MacPerl514CFM and a PPC 604e/MacOS 8.0
with MacPerl 518. Both machines have PC Exchange. With PC Exchange turned
off, no PC discs can be mounted, so at least to that extent PC Exchange
must be involved in all that follows.

The first BA PC floppy appeared to have the title "Asetup" (from the Icon
and Finder's GetInfo). However dropped onto a 'droplet', @ARGV returned
just the first two characters "As". Predictably opendir() failed (with 'No
such file or diectory') and readdir() had nothing to read. The same thing
happened on both the Powerbook and the PPC.

Since the Mac (presumably via PC Exchange) could 'see' the title (and
indeed open the disc with a double-click) I wondered if AppleScript would
work and tried the following script:

#!perl

$f = MacPerl::DoAppleScript qq(
    set vDisc to {}
    set vFiles to {}
    set vLen to 1
    tell application "Finder"
        set vDisk to every disk whose ejectable is true
        set vDisk to vDisk as list
        set vLen to length of vDisk
        repeat with i from 1 to vLen
            set vFiles to vFiles & every file of item i of vDisk
        end repeat
    end tell
    vFiles
);

$f =~ s/[{}]//g;
foreach (split(/,/, $f)) {
    s/^.*?\"(.*?)\".*?\"(.*?)\".*$/$2:$1/;
    push @f, $_
}

foreach (@f) { print "$_\n" }

It worked on both machines and with all discs.

I tried an AEBuild version of the AppleScript which for clarity's sake is
at the end of this message. It is more or less the same as the script above
but without excluding the startup disc. The AEBuild script failed on both
the Powerbook and the PPC when it came to the floppy named "Asetup" even
though (which is very curious) the full name of the file was returned.
Otherwise it worked on both machines with all the other disc.

So, in the case of floppy "Asetup", although the floppy's name could be
read by AEBuild() it was still unable to open the floppy to read the file
names. Odd.

On the _Powerbook_, the other BA floppies and the Farnell CD, all worked to
the extent that the 'droplet' returned the full name in @ARGV. Even so,
opendir() failed with the usual error message. Also odd.

On the _PPC_, the droplet worked 'normally' i.e., @ARGV returned the full
name, opendir() opened the volume, and readdir() read the file-names.

So my first guess is that there are some differences either in MacOS or in
PC Exchange which account for the different behaviour.

This left the floppy named "Asetup" as the odd one out. I wondered if it
would help if it were renamed. So I removed the name letter by letter in
the Icon, and was surprised to find it took >two< clicks to get rid of each
letter. Unfortunately in doing that I destroyed the evidence, but it seems
that there are sometimes non-printable characters in PC disc's titles.
Anyone know about this?

Having done that, and retyped "Asetup" in the title-box, the floppy then
behaved in exactly the same way as the others the others -- 'properly' on
the PPC (readdir() works) and 'improperly' on the Powerbook (readdir()
doesn't work).

To summarise it all, with the few PC discs about here (the're normally
taken out and shot at dawn) I find that:

        (a)  'AppleScript' can read the file names on a PC floppy under all
             conditons, even when there are unusual characters in the name.
             This is valid for the 68k Powerbook and the 604 PowerMac.

        (b)  An AEBuild() script will only read the file names if there are
             no unusual characters in the file name.
             This is valid for the 68k Powerbook and the 604 PowerMac.

        (c)  MacPerl's opendir()/readdir() will work with PC discs provided
             there are no unusual characters in the name but only on the
             604 PowerMac.

This seems at odds with Chris Nandor's experience unless perhaps he has
some funny characters in the disc name?

I apologise for an overlong post but hope there is something here of interest.

Alan Fry

============================== begin ==============================

#!perl
use Mac::AppleEvents;

$str = get_list('cdis', 'null()');
$obj = parse($str);
foreach (@{$obj}) { push(@new, get_list('file', $_)) }
foreach (@new) { foreach (@{parse($_)}) { print "$_\n" } }

sub get_list {
    my($type, $from) = @_;
    my $str = '';
    my $evt = '';
    my $rep = '';
    my $obj = "obj {want:type($type), from:$from, form:indx, seld:abso(all )}";
    $evt = AEBuildAppleEvent(
        'core', 'getd', 'sign', 'MACS', 0, 0, "'----':$obj, rtyp:list"
    ) or die $^E;
    $rep = AESend($evt, kAEWaitReply) or die $^E;
    $str = AEPrint(AEGetParamDesc($rep, '----'));
    AEDisposeDesc $evt;
    AEDisposeDesc $rep;
    $str
}

sub parse {
    my $str = shift;
    my $ref = '';
    my @obj = ();
    $str =~ s/\[//g;
    $str =~ s/\]//g;
    $str =~ s/}$//;
    @obj = split(/},\s*/, $str);
    foreach (@obj) { $_ .= '}'}
    $ref = \@obj;
}

=============================== end ===============================



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