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"


@cd %HOMEPATH%\My Documents

Is there a better way?

Comments (6)

  1. BlakeHandler says:

    You should add a %HOMEDRIVE% command to insure that you’re on the proper drive.


    cd %HOMEPATH%My Documents

  2. yvesdolc says:

    Thanks but I already do it. BTW, on Vista, you would need to change this to:


    @cd %HOMEPATH%Documents

  3. MSDN Archive says:

    1) 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


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

  4. Yves Dolce says:

    Thanks Jim.

    How would you use USERPROFILE?

    If you do

    D:>cd %userprofile%


    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.

  5. MSDN Archive says:

    The key point to notice is the quotes I added.

    @cd /d "%UserProfile%My Documents"

Skip to main content