Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to test whether FILE exists and is readable in D
    primarykey
    data
    text
    <p>How do you determine if a file is readable in D? I've searched both google and D's docs and stuff multiple times--I've also searched SO multiple times--but I haven't been able to find <strong>anything</strong> on testing whether a given file is readable. I know how to do it, theoretically, in C using __freadable--I even tried to make an external call to __freadable in D but I got the following linking error: </p> <pre><code>ldc2 -O2 -dw -g -wi -I/usr/include/stdio_ext.h -c ket.d ket.o ldc2 -O2 -dw -g -wi -I/usr/include/stdio_ext.h -ofket ket.o ket.o: In function `_Dmain': /home/hav3lock/sy.l/repos/pub_rel/ket/ket.d:47: undefined reference to `_D3ket4mainFAAyaZv11__freadableUPOS4core4stdc5stdio6_iobufZi' collect2: error: ld returned 1 exit status Error: /usr/bin/gcc failed with status: 1 make: *** [ket] Error 1 </code></pre> <p>I read some more on calling C stuff in D and apparently I'd need to rewrite the stdio_ext.h C header--where __freadable lives--as a D header or something like that, and that amount of work is beyond the scope of what I'm trying to do. </p> <p>I just want to be able to figure out if a given file is readable so that I can determine whether the file exists and if it is also readable all in one go. If I was writing this sucker in bash I'd just use</p> <pre><code>[[ -r FILE ]] </code></pre> <p>to test whether FILE exists and read permission to it is granted, but I just can't find out how to do the equivalent in D... any ideas? </p> <hr> <p>Tried using getAttributes, but D complains about:</p> <pre><code>no property 'getAttributes' for type 'File' </code></pre> <p>Here's how I'm using <em>getAttributes</em></p> <pre><code> auto file_a = File(proc_auto[hdex], "r"); writeln(file_a.getAttributes); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload