On Fri, 04 Mar 2011 10:13:04 -0000, Nick Sabalausky <a@a.a> wrote:
"Lars T. Kyllingstad" <public@kyllingen.NOSPAMnet> wrote in message
news:ikqabr$796$4...@digitalmars.com...


- 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.

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".

R

p.s. "copy con" means copy console, type something, then press ctrl+z to mark EOF.

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to