Windows – Where is %PUBLICDOCUMENTS%? (shell:Common Documents)

environment-variableswindows 7

I need an expansion that gives the current location of public documents. %PUBLIC% expands to C:\Users\Public, but I haven't found any equivalent for public documents.

%PUBLICDOCUMENTS%, %COMMONDOCUMENTS%, and %SHAREDDOCUMENTS% are not recognized by Windows 7. My public documents folder is not usually at %PUBLIC%\Documents, so I can't use that.

Is there one I can use? (Is there a complete list somewhere? Running set at the command line doesn't show %PUBLIC%, and I know that exists. Are there others that don't come up with set?)

Best Answer

There is no environment variable for common documents. I think you have two options:

  1. Create a variable yourself and set the value manually
  2. You figure it out dynamically when the batch file is running (I would recommend this)

For option 1, just create a variable and set the value to C:\Users\Public. See this question for more details about environment variables.

For option 2, simply read the value from the registry value HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common Documents to a variable and then use it.

Here's the command for doing this (Source: http://www.robvanderwoude.com/ntregquery.php)

FOR /F "tokens=3*" %%A IN ('REG.EXE QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /V "Common Documents" 2^>NUL ^| FIND "REG_SZ"') DO SET CommonDocs=%%B

Output:

enter image description here

Related Question