On Monday, 18 February 2013 at 07:32:06 UTC, Jacob Carlborg wrote:
On 2013-02-18 04:28, eGust wrote:
I need to locate the directory of current executable file, but
I can't
find how to do that in Phobos. I tried
core.runtime.Runtime.args[0], but
failed. Is there a standard method of Phobos to do that? I
only know the
way of Windows (GetModuleFileName), but I think as a common
task there
should be a platform-independent way to get it in the standard
library.
http://www.dsource.org/projects/tango/attachment/ticket/1536/process.d
Thanks for your reply. Does anyone know, will it be added into
D2's standard library?
p.s. About the code, I don't know how it work on other platform,
but on windows it will get a bad result if the path contains any
non-ASCII character and D1's char[] is UTF-8 encoded.
GetModuleFileNameA will get a string encoded as the ACP setting
but not UTF-8. ASCII character is well compatible with most
character sets (Windows' ACP setting) including UTF-8. But once a
non-ASCII character in the path (like me, a Chinese user, a lot
Chinese characters namd dirs on my PC, ACP is 936--GBK), it
fails. Better way is to use GetModuleFileNameW and wchar[] then
convert back to char[].
Anyway, thank you very much!