Strange behavior of read file

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Aug 27 16:03:24 PDT 2013


On Wed, Aug 28, 2013 at 12:51:12AM +0200, Ramon wrote:
[...]
> 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.
[...]

That's because '~' is expanded not by the OS but by the shell. The OS
treats it as a directory with the literal name '~', which doesn't exist.
D's file I/O functions don't go through the shell.

std.path.expandTilde is your friend. :)


T

-- 
This sentence is false.


More information about the Digitalmars-d-learn mailing list