Windows has to store the new relocated folder somewhere.
This somewhere is the registry and the following batch will read the Registry value containing the new location.
Reference
I just did a test with a VM to verify this.
@Echo off&SetLocal EnableExtensions
Set "Key=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
Set "Val={374DE290-123F-4565-9164-39C4925E467B}"
For /F "Tokens=2*" %%A in (
'Reg Query "%Key%" /v "%Val%" 2^>Nul ^| Find "%Val%" '
) Do Set "Downloads=%%B"
Echo 'Downloads' location: %Downloads%
So the batch will create the variable %Downloads%
you asked for.
Sample output with a Downloads folder moved to the root of c:
'Downloads' location: C:\Downloads
EDIT: due to spaces in the val My Music
, My Pictures
and My Video
this will solve these variants
Set "Key=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
Set "Val=My Video"
For /F "Tokens=3*" %%A in (
'Reg Query "%Key%" /v "%Val%" 2^>Nul ^| Find "%Val%" '
) Do Set "MyVideo=%%B"
Echo Possible 'My Video' location: %MyVideo%
Set "Key=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
Set "Val=My Music"
For /F "Tokens=3*" %%A in (
'Reg Query "%Key%" /v "%Val%" 2^>Nul ^| Find "%Val%" '
) Do Set "MyMusic=%%B"
Echo Possible 'My Music' location: %MyMusic%
Set "Key=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
Set "Val=My Pictures"
For /F "Tokens=3*" %%A in (
'Reg Query "%Key%" /v "%Val%" 2^>Nul ^| Find "%Val%" '
) Do Set "MyPictures=%%B"
Echo Possible 'My Pictures' location: %MyPictures%