From 7cd9a6948847ca1d270c57c2c64c05a4cf5a8840 Mon Sep 17 00:00:00 2001 From: Klein Date: Sat, 20 Dec 2025 13:34:05 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Init-DeveloperDrive.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Init-DeveloperDrive.ps1 | 50 ++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/Init-DeveloperDrive.ps1 b/Init-DeveloperDrive.ps1 index 0db91de..be78627 100644 --- a/Init-DeveloperDrive.ps1 +++ b/Init-DeveloperDrive.ps1 @@ -1,37 +1,25 @@ -# 1_Map_Dev_Caches.ps1 -$TargetBase = "D:\Data\Symlink_Storage" +# 2_Move_System_Folders.ps1 +$D_Doc = "D:\Document" -# 定义映射关系:C盘路径 = D盘子路径 -$Mappings = @{ - "$HOME\.m2" = "$TargetBase\.m2" - "$HOME\.gradle" = "$TargetBase\.gradle" - "$HOME\.npm" = "$TargetBase\npm-cache" - "$env:LOCALAPPDATA\pip\cache" = "$TargetBase\pip-cache" +# 定义注册表键名与 D 盘新路径的对应关系 +$Folders = @{ + "Desktop" = "$D_Doc\Desktop" + "Personal" = "$D_Doc\Documents" + "{374DE290-123F-4565-9164-39C4925E467B}" = "$D_Doc\Downloads" # Downloads 键名 + "My Pictures" = "$D_Doc\Pictures" } -foreach ($Source in $Mappings.Keys) { - $Destination = $Mappings[$Source] +$RegistryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" - # 如果 D 盘目标目录不存在,则创建 - if (!(Test-Path $Destination)) { - New-Item -Path $Destination -ItemType Directory -Force | Out-Null - } +foreach ($Key in $Folders.Keys) { + $NewPath = $Folders[$Key] + + # 创建 D 盘目录 + if (!(Test-Path $NewPath)) { New-Item -Path $NewPath -ItemType Directory -Force } - if (Test-Path $Source) { - # 如果 C 盘已经是符号链接,跳过 - $folder = Get-Item $Source - if ($folder.Attributes -match "ReparsePoint") { - Write-Host "[跳过] $Source 已经是映射状态" -ForegroundColor Yellow - continue - } + # 修改注册表 + Set-ItemProperty -Path $RegistryPath -Name $Key -Value $NewPath + Write-Host "[成功] $Key 路径已改为 $NewPath" -ForegroundColor Green +} - # 移动现有文件到 D 盘 - Write-Host "[处理] 正在搬移 $Source -> $Destination" -ForegroundColor Cyan - Move-Item -Path "$Source\*" -Destination $Destination -Force -ErrorAction SilentlyContinue - Remove-Item -Path $Source -Recurse -Force - } - - # 创建符号链接 (Junction) - New-Item -Path $Source -ItemType Junction -Value $Destination - Write-Host "[成功] 已建立链接: $Source" -ForegroundColor Green -} \ No newline at end of file +Write-Host "提示:请重启电脑或重新启动 Windows 资源管理器以应用更改。" -ForegroundColor Yellow \ No newline at end of file