www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Creating a file in ~/.config (ubuntu)

reply "Minas" <minas_mina1990 hotmail.co.uk> writes:
I am trying to create a file in ~/.config
My code is:

[code]
import std.stdio;

void main()
{
	auto f = File("~/.config/minas.txt", "w");
}
[/code]

However, an exception is thrown.

std.exception.ErrnoException std/stdio.d(288): Cannot open file 
`~/.config/minas.txt' in mode `w' (No such file or directory)
----------------
./test(std.stdio.File std.stdio.File.__ctor(immutable(char)[], 
const(char[]))+0x5c) [0x41a5ac]
./test(_Dmain+0x32) [0x41892a]
./test(extern (C) int rt.dmain2.main(int, char**).void 
runMain()+0x17) [0x419597]
./test(extern (C) int rt.dmain2.main(int, char**).void 
tryExec(scope void delegate())+0x2a) [0x418f0e]
./test(extern (C) int rt.dmain2.main(int, char**).void 
runAll()+0x42) [0x4195ea]
./test(extern (C) int rt.dmain2.main(int, char**).void 
tryExec(scope void delegate())+0x2a) [0x418f0e]
./test(main+0xd3) [0x418e9f]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) 
[0x7ff3dcb4830d]


When trying to create it in the current directory(~/Deskto) it 
works fine. I guess it has something to do with access rights.
Is there something I can do to run it with higher access 
priviliges?

(I know that this might not have to do with D but I thought this 
would be a good place to ask)

Thanks in advance.
Apr 13 2012
next sibling parent Kevin Cox <kevincox.ca gmail.com> writes:
Try using the $HOME environment variable.
Apr 13 2012
prev sibling parent reply Bystroushaak <bystrousak kitakitsune.org> writes:
Use std.path.expandTilde() ->
http://dlang.org/phobos/std_path.html#expandTilde

On 13.4.2012 18:02, Minas wrote:
 I am trying to create a file in ~/.config
 My code is:
 
 [code]
 import std.stdio;
 
 void main()
 {
     auto f = File("~/.config/minas.txt", "w");
 }
 [/code]
 
 However, an exception is thrown.
 
 std.exception.ErrnoException std/stdio.d(288): Cannot open file
 `~/.config/minas.txt' in mode `w' (No such file or directory)
 ----------------
 ./test(std.stdio.File std.stdio.File.__ctor(immutable(char)[],
 const(char[]))+0x5c) [0x41a5ac]
 ./test(_Dmain+0x32) [0x41892a]
 ./test(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x17)
 [0x419597]
 ./test(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope
 void delegate())+0x2a) [0x418f0e]
 ./test(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x42)
 [0x4195ea]
 ./test(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope
 void delegate())+0x2a) [0x418f0e]
 ./test(main+0xd3) [0x418e9f]
 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7ff3dcb4830d]
 
 
 When trying to create it in the current directory(~/Deskto) it works
 fine. I guess it has something to do with access rights.
 Is there something I can do to run it with higher access priviliges?
 
 (I know that this might not have to do with D but I thought this would
 be a good place to ask)
 
 Thanks in advance.
Apr 13 2012
parent "Minas" <minas_mina1990 hotmail.co.uk> writes:
On Friday, 13 April 2012 at 16:41:01 UTC, Bystroushaak wrote:
 Use std.path.expandTilde() ->
 http://dlang.org/phobos/std_path.html#expandTilde
Thank you very much! That did the trick! auto f = File(expandTilde("~/.config/test.txt","w"));
Apr 13 2012