On Thu, 06 Dec 2012 16:52:20 +0100, Suliman wrote:
> I am trying to create simple app that would read user input and open
> file with such name, but every time when I run it's crash with error
>
> "std.file.FileException@std\file.d(294): \1.txt"
>
After a call to readln, the string returned has termination characters
that need to be stripped off.
import std.stdio;
import std.file;
void main()
{
string name = readln();
while(name[$-1] == '\x0a' || name[$-1] == '\x0d')
name.length -= 1;
if(name.exists)
writeln(name, " exists!");
else
{
writeln(name, " doesn't exists!");
return;
}
auto filearray = cast(char[]) read(name);
writeln("\n", filearray);
}