开发者

How to obtain the path of Desktop in gnome

I am using gnome/Ubuntu-10.10 in Chinese language and the desktop path is not "~/Des开发者_StackOverflowktop" but "~/XXXX" where XXXX stands for the Chinese translation of "Desktop". So, how to write code to obtain the proper path of desktop regardless of the system language? I noticed Qt SDK properly added a shortcut on the desktop so I guess there is a way. Thanks a lot!


One more way to do it:

dir=$(xdg-user-dir DESKTOP)


The locations of the user directories are described in the xdg-user-dirs specification. They provide some code here that you can copy, to look up the name of the desktop directory from within your code.


If you are using Glib, you can do

const char *desktop_dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);

This properly pays attention to the XDG environment variables and all that.


echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}

works fine on a local linux drive and also when the /home/<user> is mapped to an nfs drive.


I have not tested yet, but try echo echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}, this cmd maybe do the work.


The answer is provided by xdg-user-dirs specs:

test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && source ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}
echo ${XDG_DOWNLOAD_DIR:-$HOME}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜