如何通过PowerShell或CMD修改Windows文档文件夹默认存储路径
CMD修改方案
- 先创建目标文件夹:
mkdir "C:\users\JatonJustice\desktop\testfolder" - 依次执行两条注册表修改命令:
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /f /v Personal /t REG_EXPAND_SZ /d "C:\users\JatonJustice\desktop\testfolder" reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /f /v Personal /t REG_SZ /d "C:\users\JatonJustice\desktop\testfolder"
- 重载资源管理器让配置生效,无需重启系统:
taskkill /f /im explorer.exe && start explorer.exe - 可选操作:迁移原文档目录下的所有文件到新路径:
xcopy "%USERPROFILE%\Documents\*" "C:\users\JatonJustice\desktop\testfolder" /E /H /C /Y
PowerShell修改方案
- 定义目标路径并创建目录(如果不存在):
$targetPath = "C:\users\JatonJustice\desktop\testfolder" if (-not (Test-Path $targetPath)) { New-Item -ItemType Directory -Path $targetPath -Force | Out-Null }
- 修改两项注册表配置:
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal" -Value $targetPath -Type ExpandString -Force Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" -Name "Personal" -Value $targetPath -Type String -Force
- 重载资源管理器生效:
Stop-Process -Name explorer -Force Start-Process explorer
- 可选操作:迁移原文档目录文件:
Copy-Item -Path "$env:USERPROFILE\Documents\*" -Destination $targetPath -Recurse -Force
注意事项
- 所有命令使用当前普通用户权限执行即可,无需管理员权限
- 若重载资源管理器后未立即生效,可注销当前用户重新登录
- 不要手动修改原文档目录下的
desktop.ini配置文件,避免出现路径显示异常
内容的提问来源于stack exchange,提问作者user16004320
相关产品推荐
相关产品推荐

