Strange behavior of read file

Ramon spam at thanks.no
Tue Aug 27 15:51:12 PDT 2013


I played a little with it

int f(string fileName = r"someExistingPath") {
    auto text = read(fileName);
    return text.length;
}

void main()
{
   try {
       string fileName = r"someExistingPath";
       if(exists(fileName))
          writeln("File '", fileName, "' does exist.");
       auto text = read(fileName);
       writeln(text.length);

       writeln(f);  // **** EXCEPTION HERE
    }
    catch (Exception e) {
       writeln(e);
    }

    writeln(f);
}

As you see, I mistrustingly inserted a dumb exist test before 
attempting to read.

Here's what I came up with (on linux):

- trying with filename r"~/text.txt" (i.e. an existing file in my 
home dir) it FAILED.

- trying with the same filename but this time home dir 
explicitely written out fully (r"/home/me/test.txt) it WORKED.

- your code did NOT throw where you say it does ("writeln(f)") 
but actually in the read call.

Conclusion: I assume D's OS path related mechanisms to be 
somewhat dumb. Anyway the code throws where it's supposed to, 
i.e. when confronted with a non existing (or not recognized?) 
path.


More information about the Digitalmars-d-learn mailing list