cd "My Documents"
John was complaining about this not working so I wrote MyDoc.bat:
@REM This will work if you did not redirect “My Documents"
@%HOMEDRIVE%
@cd %HOMEPATH%\My Documents
Is there a better way?
Comments
- Anonymous
April 07, 2006
You should add a %HOMEDRIVE% command to insure that you're on the proper drive.
%HOMEDRIVE%
cd %HOMEPATH%My Documents - Anonymous
April 07, 2006
Thanks but I already do it. BTW, on Vista, you would need to change this to:
%HOMEDRIVE%
@cd %HOMEPATH%Documents - Anonymous
April 07, 2006
- AFAIK you can use UserProfile instead of the separate HOMEDRIVE and HOMEPATH
2) you can change drive and path at the same time with cd /d
So:
@cd /d "%UserProfile%My Documents"
Note that either of those approaches are actually busted - the user can redirect their "my documents" to basically any arbitrary path (many in my office point it to D:My Documents) - the above is just the default location.
Now, that's likely written into HKCU somewhere, so if you wanted to support that, I'd imagine it's a reg.exe call, parse it out (perhaps with "for"), cache it into a env var (so we don't have to do the check each time :) and do the cd.
On a semi-related note, in Monad the $home variable is already set for you, and parsing the registry contents would, of course, be simpler.
- Anonymous
April 16, 2006
Thanks Jim.
How would you use USERPROFILE?
If you do
D:>cd %userprofile%
and
USERPROFILE=C:Documents and Settingsjmanning
this won't work or am I missing your point?
On my machines, I do redirect My DOCUMENTS so this batch file is actually tailored but I shall follow your suggestion about using reg.exe.
Thanks again. - Anonymous
June 10, 2006
The key point to notice is the quotes I added.
@cd /d "%UserProfile%My Documents" - Anonymous
June 10, 2006
Thanks James.