Thread overview
File I/O
May 12, 2012
Erik Weber
May 13, 2012
Walter Bright
May 13, 2012
Erik Weber
May 12, 2012
Can someone tell me how to create a file within a directory such as the user's home directory, or a directory within "Program Files", with DMC 852?

I cannot get SHGetFolderPath or SHGetKnownFolderPath to compile. Does DMC support those?

I can create a file with ofstream.open, but only in the working directory. I don't know how to prepend a path that comes from an environment variable or by querying the system for something like CSIDL_PROGRAM_FILES or what have you, only a hardcoded path. And as far as I know you can't use stuff like getpwuid on Windows.

I just want to create a config file for read/write by the executable.

Thanks,
Erik
May 13, 2012
On 5/12/2012 1:58 PM, Erik Weber wrote:
> Can someone tell me how to create a file within a directory such
> as the user's home directory, or a directory within "Program
> Files", with DMC 852?
>
> I cannot get SHGetFolderPath or SHGetKnownFolderPath to compile.
> Does DMC support those?
>
> I can create a file with ofstream.open, but only in the working
> directory. I don't know how to prepend a path that comes from an
> environment variable or by querying the system for something like
> CSIDL_PROGRAM_FILES or what have you, only a hardcoded path. And
> as far as I know you can't use stuff like getpwuid on Windows.
>
> I just want to create a config file for read/write by the
> executable.
>
> Thanks,
> Erik

Just build a string that includes the path and the file name, and pass it to fopen().
May 13, 2012
== Quote from Walter Bright (newshound2@digitalmars.com)'s article
> On 5/12/2012 1:58 PM, Erik Weber wrote:
> > Can someone tell me how to create a file within a directory
such
> > as the user's home directory, or a directory within "Program Files", with DMC 852?
> >
> > Thanks,
> > Erik
> Just build a string that includes the path and the file name,
and pass it to
> fopen().

Thanks Walter. It works. What I was unsure of was how to build the string. For now I am using getenv. Apparently the preferred way on Windows is SHGetKnownFolderPath in case environment variables don't work.

Erik