There are three possibilities for the.d test -- the file exists and is a
directory, the files exists and is not a directory, and the file does not
exist. The test needs to distinguish between these three cases.

The documentation for .d states:

Returns True if the invocant is a path that exists and is a directory. The
method will fail <https://docs.raku.org/routine/fail> with
X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

(and by implication False if the file exists and is not a directory). In
other words it is behaving exactly as specified.

If you want to allow for the possibility that the file does not exist at
all, then you either need to catch the exception, or check for file
existence first.

Something like
'p7lib'.IO ~~ :e & :d
might work, although I haven't tested it.

Kevin.


On Sat, 16 May 2020 at 20:16, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-05-15 22:30, ToddAndMargo via perl6-users wrote:
> > Hi All,.
> >
> > Windows 7, sp1, x64
> >
> >  >raku -v
> > This is Rakudo version 2020.01 built on MoarVM version
> > 2020.01.1 implementing Perl 6.d.
> >
> >
> > I am trying to get perl to tell me if a drive letter exists
> >
> > This is from Git's df command:
> >
> >  >df -kPT H:\
> > Filesystem     Type 1024-blocks  Used Available Capacity Mounted on
> > H:             ntfs       38908  9964     28944      26% /h
> >
> > So, H:\ is there
> >
> >  >raku "say H:\.IO.e"
> > Could not open say H:\.IO.e. Failed to stat file: no such file or
> directory
> >
> > And in case I need \\
> >
> >  >raku "say H:\\.IO.e"
> > Could not open say H:\\.IO.e. Failed to stat file: no such file or
> > directory
> >
> > And in case I need a forward slashL:
> >  >raku "say H:/.IO.e"
> > Could not open say H:/.IO.e. Failed to stat file: no such file or
> directory
> >
> > What am I doing wrong, this time?
> >
> > -T
> >
>
>
> As far as I can tell IO.e and IO.d is completely trashed
> in Windows:
>
> K:\Windows\NtUtil>dir H:
>   Volume in drive H is BACKUP
>   Volume Serial Number is 00D0-CAD4
>
>   Directory of H:\
>
> 05/15/2020  22:21                 0 IAmBackup
> 05/15/2020  22:43    <DIR>          MyDocsBackup
>                 1 File(s)              0 bytes
>                 1 Dir(s)      29,638,656 bytes free
>
>
>
> K:\Windows\NtUtil>raku "say 'h://IAmBackup'.IO.e"
> Could not open say 'h://IAmBackup'.IO.e. Failed to stat file: no such
> file or di
> rectory
>
> K:\Windows\NtUtil>raku "say 'h:/IAmBackup'.IO.e"
> Could not open say 'h:/IAmBackup'.IO.e. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h:\IAmBackup'.IO.e"
> Could not open say 'h:\IAmBackup'.IO.e. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h:\\IAmBackup'.IO.e"
> Could not open say 'h:\\IAmBackup'.IO.e. Failed to stat file: no such
> file or directory
>
>
> And that goes for IO.d too:
>
> K:\Windows\NtUtil>raku "say 'h:\\MyDocsBackup'.IO.d"
> Could not open say 'h:\\MyDocsBackup'.IO.d. Failed to stat file: no such
> file or
>   directory
>
> K:\Windows\NtUtil>raku "say 'h:\MyDocsBackup'.IO.d"
> Could not open say 'h:\MyDocsBackup'.IO.d. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h:/MyDocsBackup'.IO.d"
> Could not open say 'h:/MyDocsBackup'.IO.d. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h://MyDocsBackup'.IO.d"
> Could not open say 'h://MyDocsBackup'.IO.d. Failed to stat file: no such
> file or  directory
>
> This gets a TRIPLE:  :'(  :'(  :'(
>
>
>
> And it only works slightly better under Fedora:
>
> $ p6 'say "GetOptLongTest.pl6".IO.e'
> True
>
> $ p6 'say "GetOptLongTest.pl7".IO.e'
> False
>
> $ p6 'say "p6lib".IO.d'
> True
>
> $ p6 'say "p7lib".IO.d'
> Failed to find '/home/linuxutil/p7lib' while trying to do '.d'
>    in block <unit> at -e line 1
>
> Notice that it crashed instead of returning a False.
>
> This gets a single :'(
>
> <editorial comment> AAAAAAHHHHHH!!!! </editorial comment>
>

Reply via email to