Default path to Desktop with vista
-
Hi everyone. I'm a newbee that's exhausted the Internet already, so I joined the forum. I'm attempting to create a file on the Desktop under the Vista environment, which is not user dependent. e.g ofstream file; file.open("c:\\%userprofile%\\Desktop\\report.txt"); if (!file){ cerr <<"Unable to open file report.txt"; exit(1); } but cannot seem to make this happen on the c drive (desktop). Thanks in advance.
-
Hi everyone. I'm a newbee that's exhausted the Internet already, so I joined the forum. I'm attempting to create a file on the Desktop under the Vista environment, which is not user dependent. e.g ofstream file; file.open("c:\\%userprofile%\\Desktop\\report.txt"); if (!file){ cerr <<"Unable to open file report.txt"; exit(1); } but cannot seem to make this happen on the c drive (desktop). Thanks in advance.
You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps
-
You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps
CoderGirl42 wrote:
...but it will expand the %userprofile% to it's actual value.
Unless it contains spaces.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps
I see the expansion in which you are speaking of from the cmd window. However, since %userprofile% yields the msg. "...' is not recognized as an internal or external command, operable program or batch file.", I'm wondering if this is the same reason %userprofile% does not work from within my program. I'm beginning to think it's the vista platform :((
-
You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps
-
Maybe stupid but if you open a DOS-window and type in SET (enter) is your userprofile there? Rozis
Sorry to say this but I believe you are misunderstanding the use of environment variables. Apart from the fact that the string you are using is wrong ( the variable already contains the drive letter and as already pointed out may contain spaces) do you know the call you are making with apply environment variable expansion? I prefer not to leave things to chance by either calling, ExpandEnvironmentStringsForUser - "http://msdn.microsoft.com/en-us/library/bb762275(VS.85).aspx" or SHGetFolderPath - "http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx" Alan