"Regan Heath" <[email protected]> wrote in message
news:[email protected]...
> On Fri, 04 Mar 2011 10:13:04 -0000, Nick Sabalausky <[email protected]> wrote:
>> "Lars T. Kyllingstad" <[email protected]> wrote in message
>> news:[email protected]...
>>>
>>>>
>>>> - Windows *does* have a concept of a home dir, so maybe tilde should be
>>>> expanded even on Windows. Only problem though is that Windows has *two*
>>>> main home dirs for each user: %HOMEPATH% for user-created files and
>>>> %APPDATA% for application data. (And some others, but I don't think any
>>>> of the others are appropriate for "~") So maybe there should be these
>>>> three:
>>>>
>>>> 1. expandTilde: Exactly as it is now: expands ~ on posix, no-op
>>>> on
>>>> windows.
>>>>
>>>> 2. expandHomeDir: On posix: Expands "~" and "%HOMEDIR%" to the
>>>> user's home directory. On windows: Expands "~" and "%HOMEDIR%" to
>>>> whatever %HOMEDIR% is set to.
>>>>
>>>> 3. expandAppDataDir: On posix: Expands "~" and "%APPDATA%" to
>>>> the
>>>> user's home directory. On windows: Expands "~" and "%APPDATA%" to
>>>> whatever %APPDATA% is set to.
>>>
>>> On POSIX you expect to be able to use ~ anywhere you're asked to input a
>>> path/filename. Is this the case on Windows? Can you write %HOMEDIR%
>>> \report.doc in Word's "Open" dialog, for instance?
>>>
>>
>> No, it's just an environment variable.
>
> Actually, you can. I just tried Textpad and Word 2010 and both accepted
> me typing:
>
> %HOMEDRIVE%%HOMEPATH%\ (at this point they both bring up suggestions)
> %APPDATA%\ (at this point they both bring up suggestions)
>
> FYI.. my environment variables are:
>
> APPDATA=C:\Users\rheath.<domain>\AppData\Roaming
> HOMEDRIVE=C:
> HOMEPATH=\Users\rheath.<domain>
>
> I don't have HOMEDIR, .. this is on Windows 7 x64 BTW.
>
Oh, you're right. It's the same for me on XP. I must have misread the doc
page: There is no %HOMEDIR%, that's why it didn't work when I tried it in
notepad. The correct thing is %HOMEDRIVE%%HOMEPATH%. That works for me, and
so does %APPDATA%.
>> In fact, it seems that % is a valid
>> filename character (I wouldn't have even guessed that), so expanding any
>> of
>> the %BLAH% stuff in std.path is probably a bad idea after all.
>
> Not necessarily, but it might require a bit more double-checking, for
> example..
>
> If you type the following at command prompt you get an error.
> copy con test%HOMEDRIVE%.txt
>
> "The filename, directory name, or volume label syntax is incorrect."
>
> Because %HOMEDRIVE% is expanded to C: and testC:.txt is invalid.
>
> But these both work:
> copy con test%HOMEDRIVE.txt (missing 2nd %)
> copy con test%HOMEDRIV%.txt (non-existant envvar)
>
> In the latter case you actually get a file named "test%HOMEDRIV%.txt", it
> hasn't attempted to replace the non-existant envvar with a blank string,
> as that would result in "test.txt".
>
FWIW, I just did a little test to see if the substitution is being done by
the commandline itself or by the command being run. Seems to be the
commandline itself doing the substitution. Make a little echo program in D:
import std.stdio;
void main(string[] args) {
writeln(args[1]);
}
>dmd main.d
>main %APPDATA%
C:\Documents and Settings\Nick Sabalausky\Application Data
Next thing to test would be the file I/O API. I'm wondering if passing
"%APPDATA%" directly to the file I/O routines would be taken literally or
get automatically expanded. I would think it would be taken literally, but
with all the magic that windows does, I'm not so sure. Don't have time to
test it at the moment.