Windows Command Prompt – Get Relocated User’s Documents Folder

cmd.execommand linewindowswindows 10

I'm trying to write a simple batch script that copies some files from the %userprofile%\Documents directory.
I'm testing the script on my machine, but after some failures I realized that I moved my user's data to a separate partition. Therefore, %userprofile%\Documents is empty, and (obviously) nothing is copied.

I already tried other environment variables such as %homedrive% and %homepath%, but they still point at the standard C:\...

Is there a way to find out the actual drive used for the user's data?

I'm using Windows 10.

Thanks!

EDIT

As pointed out by Ƭᴇcʜιᴇ007, I didn't move the user's data to another partition, but I just relocated the "main" folders (Documents, Videos, …) to some corresponding folders on another partition: right-click on (e.g.) Documents, Properties, Path.

How can I find out the path of a Document folder which has been relocated in this way?

Best Answer

Unfortunately, there's not a simple environment variable you can check from a batch script if you've redirected this from the default path relative to your profile. You can see the full list of environment variables (including some undocumented) here:

http://ss64.com/nt/syntax-variables.html

Another thing to keep in mind is folder redirection even allows you to move these to a network share. There doesn't have to be a "drive" you can use all; it might just be a UNC path.

The good news is the information you want is available at the following registry location:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal

There's a whole set of folders you can move around in that User Shell Folders key, but to read the My Documents folder here using Windows Batch looks like this:

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal

On my machine this produces the following output, which may be more or less useful to you depending on what you need and how good you are with Windows Batch scripts:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
    Personal    REG_EXPAND_SZ    C:\Users\joel\Documents

You can also try vbscript:

Set wshshell = CreateObject("WScript.Shell")
Documents = wshShell.SpecialFolders("MyDocuments")

or Powershell:

[Environment]::GetFolderPath('MyDocuments')

This may eventually be available via bash on Windows, too (really!), but I haven't seen how to do it yet in a way that will be consistently accurate.

Related Question