Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.