批量评估重新定位的Shell文件夹的位置 [英] Evaluate location of relocated shell folders with batch
问题描述
通常,您可以像这样指定变量:%USERPROFILE%\Downloads
Typically you can just specify the variable like that: %USERPROFILE%\Downloads
但是如果您将下载"文件夹移动到另一个位置,则无法使用:
But it does not work if you moved the Downloads folder to another location:
%Downloads%
作为独立变量不起作用.文件夹的正确变量是什么,因此我可以在批处理中指定该变量,然后在不修改该批处理的情况下在其他系统上使用该批处理?
%Downloads%
as a standalone variable does not work. What is the correct variable for the folder so I can specify it inside a batch and use the batch on different systems without modifying it?
推荐答案
Windows必须将新重定位的文件夹存储在某处.
这是注册表的某个位置,随后的批处理将读取包含新位置的注册表值.
参考
我刚刚对VM进行了测试,以验证这一点.
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%
因此批处理将创建您要求的变量%Downloads%
.
将Downloads文件夹移至c:根目录的示例输出
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
由于val My Music
,My Pictures
和My Video
中的空格
这将解决这些变体
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%
这篇关于批量评估重新定位的Shell文件夹的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!